Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View cararemixed's full-sized avatar
🏳️‍🌈

Cara Mitchell cararemixed

🏳️‍🌈
View GitHub Profile
zero:Scratch brian$ ruby --version # Should be similar on all versions of MRI
ruby 1.9.3dev (2010-06-30 trunk 28489) [x86_64-darwin10.4.0]
zero:Scratch brian$ ruby secure_cmp.rb
Rehearsal ------------------------------------------
binary 4.020000 0.000000 4.020000 ( 4.012945)
hash 2.180000 0.000000 2.180000 ( 2.187391)
--------------------------------- total: 6.200000sec
user system total real
binary 4.010000 0.010000 4.020000 ( 4.003827)
var vows = require('vows');
vows.describe('Deep Thought', {
topic: function () {
this.thought = new DeepThought; // prototypical scopes
},
'thought is logical': [
'define axioms' : {
topic: function () {...},
'assert something': function () {...}
var http = require('http'),
url = require('url'),
mylog="log:\r\n";
function log(str) {
mylog += str + "\r\n";
}
var server = http.createServer(function (request, response) {
switch (url.parse(request.url).pathname) {
@cararemixed
cararemixed / transaction.rb
Created December 17, 2010 22:41
Redis transactions
def transaction
# pre transaction
REDIS.MULTI
# transaction
rescue
REDIS.DISCARD
# transaction failure
raise
else
REDIS.EXEC
NoMethodError: undefined method `extend_object' on nil:NilClass.
kernel/delta/kernel.rb:85:in `extend_object (method_missing)'
kernel/common/kernel.rb:413:in `extend'
kernel/common/array.rb:1370:in `reverse_each'
kernel/common/kernel.rb:412:in `extend'
# extend is being called on a proc with a simple module. Rails reloading causing this? Rubinius quirk?
@cararemixed
cararemixed / session.rb
Created January 3, 2011 19:13
irb session
rbx-head :001 > class MyProc < Proc; end
=> nil
rbx-head :002 > MyProc.new {}.class
=> Proc
@cararemixed
cararemixed / extra.rb
Created January 3, 2011 19:16
extra argument to proc
class ExtraProc < Proc
attr_reader :extra
def initialize(extra, &b)
@extra = extra
super(&b)
end
end
@cararemixed
cararemixed / concept.sass
Created January 5, 2011 21:51
pattern matching specialization
@mixin some_sprite($state) {
background-image: url(...);
/* etc... */
}
@mixin some_sprite(default) {
background-position: 0px 18px;
}
@mixin some_sprite(hover) {
background-position: 18px 18px;
}
@mixin some_sprite($state) {
background-image: url(...);
background-position: if($state is hover, 18px, 0px) 18px;
}
// somewhere down the line ..........
.thingy {
@include some_sprite(default);
}
@cararemixed
cararemixed / smart.js
Created January 10, 2011 20:56
Very nice handling by CoffeeScript
(function() {
var Foo, a;
var __slice = Array.prototype.slice;
Foo = (function() {
function Foo() {}
return Foo;
})();
a = [1, 2, 4];
(function(func, args, ctor) {
ctor.prototype = func.prototype;