Categories
Uncategorized

XMLHttpRequest access-control-allow-origin cocoa webview

Yes, those are the search terms that had me scratching my head for several hours today…

You see, once upon a time, we trusted each other on the internet. Internet browsers were built optimistically, that no one would try to do foolish things or cheat anyone.

And then came cross-site scripting attacks. That’s where a nice site, like a banking site, gets attacked remotely simply by virtue of someone making an exploit in a comment field or some other innocuous thing. The browser would start sending data to another computer. That is bad.

So browsers got less trusting. They won’t let you send data to another computer unless that computer says it’s okay. (Wait.. what? Isn’t that backwards?) Oh, ok, so that kind of attack is still possible.

But what it does do is protect you from fake sites (e.g. a domain name where they start out recognizable, like www.mybank .. but then instead of going to dot-com, they go to dot-flibbertygibbet.com..)

But today I wasn’t trying to steal your credit card numbers. Honest. I was trying to make a webview control in a Mac app send some data to a server. It was almost working but I kept getting the error


access-control-allow-origin

Searching the internet wasn’t helpful. But I finally found the answer:


[WebView registerURLSchemeAsLocal:request.URL.scheme];

This was really handy, because I was using NSURLProtocol to deliver content via a custom sheme anyhow. But that’s a story for another day.

I hope someone finds this useful.

Categories
Uncategorized

Ignore SIGPIPE in LLDB

Both GDB and LLDB by default will stop when a debugged process receives a signal. Some libraries, such as the mongoose HTTP server, will generate SIGPIPE as a matter of course and that can be “normal”. However, the debuggers stop anyhow.

Google result currently shows this GDB command can be entered to stop the behavior:

handle SIGPIPE nostop

The LLDB equivalent is not obvious, but I found that this will do it:


process handle SIGPIPE -n true -p true -s false

Categories
Uncategorized

Plumb Foolish

You ever get that sinking feeling that this is going to happen to you?

PlumbFoolish

Categories
Uncategorized

Pobody’s Nerfect

I woke up this morning remembering that silly phrase, “Pobody’s Nerfect”, which my grandmother had on display in her home. I’m not sure of its origin. Funny the things you remember.

Categories
Uncategorized

Set Volume on Raspberry PI

This sets output to 100%, which seems the best for driving an amplifier:

amixer set PCM -- 100%

use smaller numbers to get quieter, and 0% to mute. Thanks to Joe (see comments) for finding a simpler solution than my original post.

Categories
Uncategorized

Botnet Attacks

The other day I noticed lots of hits to wp-login.php on my WordPress install. So I moved it to a new filename, and wrote a quick php file that appends the POST data received to a file. Actually, I used a linux “named pipe” so I could then run the command “cat” to print out what was being sent as it came in. I considered capturing all the attempted passwords and ip addresses, they might be useful…. but I lost interest. I got enough joy by just watching the server log fill with 404 responses.

Categories
Uncategorized

SQLite IS NULL vs IS NOT NULL query time

Today we were discussing SQLite query performance with respect to “IS NULL”. We are either misremembering, or SQLite has gotten better.

“IS NULL” will leverage an index on a column, just the same as comparing with any other value, such as “== 0”. So, it appears that NULL is indexed. IS NOT NULL, however, is only marginally helped by an index.

Evidence: save attached test.sql and run. Notice how the timing for the query drops from 95ms to 54ms for both “x == 0” as for “x IS NULL” with the addition of an index. The “x IS NOT NULL” query drops only minutely, from 95ms to 85ms.

sqlite3 test2.db < test.sql
SETUP
INSERT 1,000,000 rows, about 50% of which are, randomly NULL, the others are 0
turn on timer
baseline timings with NO INDEX for IS NULL
499969
CPU Time: user 0.095477 sys 0.003140
baseline timings with NO INDEX for IS NOT NULL
500031
CPU Time: user 0.091441 sys 0.003123
baseline timings with NO INDEX for == 0
500031
CPU Time: user 0.094747 sys 0.002805
Create index on x
baseline timings with INDEX for IS NULL
499969
CPU Time: user 0.054242 sys 0.001700
baseline timings with INDEX for IS NOT NULL
500031
CPU Time: user 0.085374 sys 0.002607
baseline timings with INDEX for == 0
500031
CPU Time: user 0.053888 sys 0.001612

SQL:
SELECT “SETUP”;
DROP TABLE IF EXISTS numerals;
CREATE TABLE numerals ( N );

INSERT INTO numerals VALUES ( 0);
INSERT INTO numerals VALUES ( 1 );
INSERT INTO numerals VALUES ( 2 );
INSERT INTO numerals VALUES ( 3 );
INSERT INTO numerals VALUES ( 4 );
INSERT INTO numerals VALUES ( 5 );
INSERT INTO numerals VALUES ( 6 );
INSERT INTO numerals VALUES ( 7 );
INSERT INTO numerals VALUES ( 8 );
INSERT INTO numerals VALUES ( 9 );

DROP TABLE IF EXISTS test;
CREATE TABLE test ( x );

SELECT “INSERT 1,000,000 rows, about 50% of which are, randomly NULL, the others are 0”;

INSERT INTO test select NULLIF(random()>0,1) FROM numerals AS A, numerals AS B, numerals AS C, numerals AS D, numerals AS E, numerals AS F;

SELECT “turn on timer”;

SELECT “baseline timings with NO INDEX for IS NULL”;
.timer on
select COUNT( rowid ) FROM test WHERE x IS NULL;
.timer off
SELECT “baseline timings with NO INDEX for IS NOT NULL”;
.timer on
select COUNT( rowid ) FROM test WHERE x IS NOT NULL;
.timer off
SELECT “baseline timings with NO INDEX for == 0”;
.timer on
select COUNT( rowid ) FROM test WHERE x == 0;
.timer off

SELECT “Create index on x”;
CREATE INDEX test_x ON test (x );

SELECT “baseline timings with INDEX for IS NULL”;
.timer on
select COUNT( rowid ) FROM test WHERE x IS NULL;
.timer off
SELECT “baseline timings with INDEX for IS NOT NULL”;
.timer on
select COUNT( rowid ) FROM test WHERE x IS NOT NULL;
.timer off
SELECT “baseline timings with INDEX for == 0”;
.timer on
select COUNT( rowid ) FROM test WHERE x == 0;
.timer off

Categories
Uncategorized

Unable to locate WordPress Plugin directory

I host multiple blogs on my site, but not enough instances that I remember all the details of how to set them up.

This error had me going for an hour or so: Plugin could not be deleted due to an error: Unable to locate WordPress Plugin directory

The reason was that the user for that blog was not a member of the www-data group.

Simple:
sudo addgroup newusername www-data

Fixed.

Categories
Uncategorized

Elegy for English Horn by Jack Stamp

Yesterday I performed the Elegy for English Horn by Jack Stamp with the Star of the North Concert band. We played at Edinborough Park in Edina, MN. There was some drama, as the venue was double booked, and the Golden Valley Orchestra was already on stage, decked in their finest tuxedos when we arrived. But unfortunately for them, their concert master was unable to come, and so they canceled their performance! So we flew on stage and performed!

Anyhoo, here’s the recording of the English Horn Solo by Jack Stamp:

Elegy for English Horn by Jack Stamp

Categories
Uncategorized

How to Transpose a Viola part for English Horn

Here is how to transpose a viola part written in “C” clef for English horn.

Summary: To make an English horn produce a concert pitch, play the note that is 7 semitones higher. Often you want to simultaneously go down an octave — in which case play 5 semitones lower.

Viola plays in “C” clef. It has it’s notes written one semitone lower on the staff. Oh, and one octave. So “middle c” is on the center line of the staff.

Armed with those facts, here is my recipe for tranposing a viola part written in “C” clef on the fly for English horn. First, look at the note as if it were treble clef (realizing it’s actually an octave less one line lower than it appears) then move it down TWO spaces or lines, and add a sharp to the key signature.

E.g. Suppose it looks like a ‘b’ and there are no sharps or flats in the key signature. (In viola’s “C” clef that isn’t a ‘b’ — the middle line is really a ‘c’ concert.) EH plays in “F”, so we must transpose down. The clef already moved it down one line, so we go down TWO more from ‘b’ to arrive at ‘G’.

Let’s take another example: Suppose the note looks like ‘a’. To a violist who knows the “C” clef, they would say, no, that looks like a ‘b’ — and they are right. To play a concert ‘b’ on an English horn, go down three and add a sharp. So it’s time to play an “F SHARP”. Simple!

A related, helpful shortcut: The same number of fingers rule!

When transposing a “C” part in TREBLE clef for English horn: If the note looks as though you’d play it with 1/2/3 fingers of the left hand as written, simply finger 1/2/3 fingers on the right. E.g. ‘b’ is one finger down. So is F#.

EDIT: The first time I wrote this I got thoroughly confused between how to transpose from Treble Clef vs how to transpose from “C” Clef. I think it’s correct now.