Skip to content

Instantly share code, notes, and snippets.

View dsamarin's full-sized avatar

Devin Samarin dsamarin

View GitHub Profile
@dsamarin
dsamarin / countries.dat
Created January 11, 2012 02:07
Country population data
1 | China | 1.35 billion people
2 | India | 1.21 billion people
3 | United States | 309 million people
4 | Indonesia | 233 million people
5 | Brazil | 195 million people
6 | Pakistan | 185 million people
7 | Bangladesh | 164 million people
8 | Nigeria | 158 million people
9 | Russia | 140 million people
10 | Japan | 127 million people
@dsamarin
dsamarin / config.json
Created January 7, 2012 07:15
Example Diaptoval configuration file
{
"Core": {
"socket": "/tmp/diaptoval.sock"
},
"IRC": {
"default": {
"nick": ["eboy", "eboyjr", "eboyjr_"],
"quit_message": "Try out lic, the IRC client, for free at http://github.com/oftn/lic/"
},
"servers": [
Hub.init = function() {
this.load_config (function() {
this.start_server ();
});
};
Hub.load_config = function(callback) {
var config, locations, self = this;
config = new HubConfig;
@dsamarin
dsamarin / gist:1518849
Created December 25, 2011 07:28
Flood control queue
/* Connection#send: Sends a message with flood control */
Connection.prototype.send = function(message) {
var queue, now;
now = Date.now();
queue = this.message_queue;
/* If the last message was sent early enough... */
if (this.message_time < (now - this.message_speed)) {
@dsamarin
dsamarin / js_direct.js
Created October 16, 2011 03:16
CPS Transforms in JavaScript and Scheme
// Example 1
function pyth(x, y) {
return Math.sqrt (x*x + y*y);
}
// Example 2
function factorial(n) {
if (n === 0) {
return 1;
}
@dsamarin
dsamarin / gist:1260689
Created October 4, 2011 01:10
C Translation Phases
1. Map characters to source character set (not relevant)
2. Trigraph sequences replaced (no one cares, low priority)
3. Backslash followed by newline deleted
4. Decomposed into tokens
5. Preprocessing directives executed
6. Macros expanded
7. _Pragma execution
@dsamarin
dsamarin / Complex.js
Created October 3, 2011 03:11
Complex numbers in JavaScript
var Complex = function(real, imag) {
if (!(this instanceof Complex)) {
return new Complex (real, imag);
}
if (typeof real === "string" && imag == null) {
return Complex.parse (real);
}
this.real = Number(real) || 0;
@dsamarin
dsamarin / Integer.js
Created October 3, 2011 03:07
Arbitrary-precision numbers in JavaScript
"use strict";
// http://kickjava.com/src/java/math/MutableBigInteger.java.htm
String.prototype.repeat = function(i) {
var d = '', t = this;
while (i) {
if (i & 1) {
d += t;
}
@dsamarin
dsamarin / lolwat.js
Created August 18, 2011 10:58 — forked from mathiasbynens/lolwat.js
Fun with v8’s Number#toString bug
var fs = require('fs');
var repl = require('repl');
console.log("Loading dictionary...");
var words = fs.readFileSync("/usr/share/dict/american-english-small", "ascii");
var wordlist = {};
var regex = /[a-z]{4,}/g;
var match;
@dsamarin
dsamarin / TextLayout.js
Created August 16, 2011 11:33
Text Rendering/Wrapping for HTML5 Canvas
suit.TextLayout = function SUITTextLayout() {
suit.Object.call(this);
/* This stores key/value pairs where the key is the width of a rendered
layout and the value is the number of lines the layout will take. */
this.wrapped_length_cache = [];
this.em_width = this.text_width("M");
};