Skip to content

Instantly share code, notes, and snippets.

View stephank's full-sized avatar

Stéphan Kochen stephank

View GitHub Profile
# A monkey-patch for ActionPack, which takes into account a POST's encoding.
# Browsers may specify this using a hidden _charset_ field, or in the Content-Type.
# Briefly tested on Rails 2.3.5 and Ruby 1.9.1p376.
class ActionController::Request < Rack::Request
# This is copied from Rack::Request. Rails overrides content_type, which the original relies on,
# thus breaking it, unfortunately. Instead, this version uses @env['CONTENT_TYPE'].
def media_type_params
return {} if @env['CONTENT_TYPE'].nil?
@env['CONTENT_TYPE'].split(/\s*[;,]\s*/)[1..-1].
class Model
# Method used in a class context.
@has_many = (names) ->
# Define the accessor method.
@[names] = ->
# Retrieve stuff from table 'names'
class Account extends Model
@has_many 'emails'
# Reverse apply.
Object::apply = (func, args) -> func.apply this, args
# Base model class.
class Model
has_many: (what) ->
@[what] = ->
how_many = @["number_of_#{what}"]
console.log "I have #{how_many} shiney #{what}!"
{puts} = require 'sys'
MyClass = prototype ~>
@doSomething = -> 3 + 5
foobar = new MyClass()
puts foobar.doSomething()
AnotherClass = prototype inherits MyClass ~>
constructor = -> @abc = 3
(function () {
var myModule = {
"prop1" : "some value",
"prop2" : "some other value"
};
myModule.someMethod = function () {
// Do stuff with props.
};
#!/usr/bin/env node
'use strict';
// The master must be reasonably stressed for the crash to appear. These
// parameters can be tweaked to accomplish that. Increasing them too far can
// cause backlog fill and undesirable connection resets.
//
// These particular values seem to work on Ubuntu 15.04 running on an EC2
// c3.large instance with official node.js 4.1.0 binaries. (Everything 64-bit)
var WORKERS = 50;
static int EIO_AfterDrawMap(eio_req *req) {
HandleScope scope;
drawmap_request *drawmap_req =(drawmap_request *)req->data;
ev_unref(EV_DEFAULT_UC);
drawmap_req->map->Unref();
Local<Value> argv[2];
if (drawmap_req->data != NULL) {
Buffer * buffer = Buffer::New(drawmap_req->data, drawmap_req->size, FreeImageBuffer, NULL);
@stephank
stephank / typed-array-copy.js
Created April 12, 2012 20:12
TypedArray#set copy test
// console runnable test case adapted from:
// https://github.com/stephank/node-arrays/blob/master/test/typed-array-copy.js
function assertEq(desc, a, b) { console.log(desc + ": " + a + " == " + b + " ? " + (a == b)); }
a = new Uint16Array(8);
b = new Uint8Array(a.buffer, 0, 2);
b[0] = 0x05;
b[1] = 0x05;
@stephank
stephank / include.gypi
Created May 1, 2012 19:30
GYP product_dir with dependencies
{
"target_defaults": {
"product_dir": "products"
}
}
@stephank
stephank / gist:3193920
Created July 28, 2012 16:30
server-time client capability specification

server-time client capability specification

Clients indicate support for the extension by requesting a capability server-time as per the [IRC Client Capabilities Extension][caps].

CAP REQ :server-time

After requesting the capability, clients MUST be able to parse an optional timestamp at the start of each message. The message pseudo-BNF, as defined in [RFC 1459, section 2.3.1][rfc1459] is extended to look as follows:

::= ['@' ] [':' ]