This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* An excerpt from https://github.com/pcacjr/bluez/blob/c70a4afe4328053f462d8e30a0a787245aa7b948/src/event.c#L132 | |
*/ | |
static size_t decode_hex(const char *pin, char *out) | |
{ | |
size_t i; | |
for (i = 0; i < 16 && pin[i * 2] && pin[i * 2 + 1]; i++) | |
sscanf(&pin[i * 2], "%02hhX", &out[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fruit { | |
var name = "Fruit" | |
var description : String { | |
return name | |
} | |
} | |
class Apple : Fruit { | |
init() { | |
super.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "System Events" | |
repeat with theProcess in (every process) | |
if name of theProcess is "emulator64-arm" then | |
set the position of (every window of theProcess) to {0, 0} | |
end if | |
end repeat | |
end tell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* I'm trying to write Core Image filter kernel functions in Quartz Composer, | |
* but it's crashing consistently on certain pieces of code that should be fine. | |
*/ | |
// This works fine: | |
kernel vec4 coreImageKernel(sampler image, __color color1) { | |
vec4 inputColor = sample(image, samplerCoord(image)); | |
return inputColor; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Runs the bootbeepASM methods and then converts the audio data to a WAVE file. | |
* @returns {Buffer} a Buffer containing the contents of a WAVE file. | |
*/ | |
var bootbeep = function() { | |
// 22050 Hz is an approximation of the Mac's 370 * 60.15 Hz = 22255.5 Hz. | |
var writer = new WaveWriter(1.5, 22050, 8); | |
var samples = bootbeepASM(); | |
console.log("Copying samples to WAVE."); | |
var i = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sineWave = function(frequency) { | |
var writer = new WaveWriter(2.0, 11025, 8); | |
var time = 0; | |
var sample = 0; | |
do { | |
sample = Math.sin(frequency * time * 2 * 3.14159); | |
time = time + 1/11025; | |
} while (writer.writeSample(sample)); | |
writer.close(); | |
return writer.buffer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates a helper to write a WAVE file to a Buffer. | |
* @param {Number} seconds - The length of the WAVE file to write. | |
* @param {Number} sampleRate - The sample rate in Hz, such as 44100 for a CD. | |
* @param {Number} bitsPerSample - Either 8 or 16. | |
*/ | |
var WaveWriter = function(seconds, sampleRate, bitsPerSample) { | |
this._sampleRate = sampleRate; | |
this._bitsPerSample = bitsPerSample; | |
this._writer = new BufferWriter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Lets you fill a Buffer without having to know its size beforehand. | |
*/ | |
var BufferWriter = function() { | |
this._size = 0; | |
this._buffer = new Buffer(100); | |
}; | |
_.extend(BufferWriter.prototype, { | |
buffer: function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adapted from http://folklore.org/projects/Macintosh/more/BootBeep.txt | |
* A direct translation of the m68k asm into JavaScript. | |
* @returns {Buffer} a Buffer which corresponds to the audio buffer on the | |
* original Macintosh, repeated for the duration of the boot beep. The Buffer | |
* contains a series of words, where the lower byte of each word is the | |
* amplitude of the audio signal at this point. | |
*/ | |
var bootbeepASM = function() { | |
d3 = 40; // D3 contains the duration: 40 is boot beep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef void (^eBlock)(); | |
eBlock exampleE_getBlock() { | |
char e = 'E'; | |
void (^block)() = ^{ | |
printf("%c\n", e); | |
}; | |
return block; | |
} |
NewerOlder