Skip to content

Instantly share code, notes, and snippets.

class QuestionsController < RestfulController
model Question
end
@qwzybug
qwzybug / after.rb
Created February 25, 2009 23:30
Refactoring a Shoes widget. Needs midiator gem.
class Piano < Widget
def initialize opts = {}, &action
opts = {:width => 700, :height => 100}.merge opts
@action = action
key_width = opts[:width] / 52.0
ivory = {:bottom => 0, :width => key_width.round, :height => opts[:height] * 2 / 5}
ebony = {:top => 0, :width => (key_width * 2 / 3).round, :height => opts[:height] * 3 / 5}
last_x = -key_width
-- this version doesn't need prototype.lua
BarGraph = {
x = 0, y = 20,
width = 20, height = 100,
offset = 0,
update =
function (self, t)
self.height = 60 + 40 * math.sin(self.offset * math.pi / 10 + t / 10)
end
Plank = {}
Plank.new = function(world, x, y, w, h, offset)
body = love.physics.newBody(world, 0, 0, 0)
body:setAngularDamping(1000)
shape = love.physics.newRectangleShape(body, x, y, w, h)
body:setMassFromShapes()
return {
shape = shape, body = body, offset = offset,
force =
function(self, t)
Glaukopis-Athena:Desktop d$ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -S -o ben.arm -arch arm -I/usr/include ben.c
In file included from /usr/include/sys/_types.h:33,
from /usr/include/_types.h:27,
from /usr/include/stdio.h:64,
from ben.c:1:
/usr/include/machine/_types.h:36:24: error: arm/_types.h: No such file or directory
In file included from /usr/include/_types.h:27,
from /usr/include/stdio.h:64,
from ben.c:1:
/usr/include/sys/_types.h:94: error: syntax error before ‘__darwin_blkcnt_t’
@interface NSData (NSData_HexAdditions)
- (NSData *)dataFromHexString;
@end
#define IS_HEX(c) ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >='A' && c <= 'F'))
@implementation NSData (NSData_HexAdditions)
/*
* Takes an NSData encoding an ASCII string representing hexadecimal data,
#!/usr/bin/env ruby
# Solve a Joel problem
def chain k
s, c, l = k, 0, [] # start, carry, digit list
begin
l.unshift k
d = 2 * k + c
c, k = d / 10, d % 10
#include <iostream>
void handle_note_off(void * channel, void * note, void * velocity);
class RadMidi {
public:
void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity)
{
handle_note_off(&channel, &note, &velocity);
}
## Implementation
class FormBuilder
def initialize obj, ctx
@obj, @ctx = obj, ctx
end
def method_missing m, *args
@ctx.send(m, @obj, *args)
end
end
Glaukopis-Athena:Desktop d$ mkdir hgcase
Glaukopis-Athena:Desktop d$ cd hgcase
Glaukopis-Athena:hgcase d$ hg init
Glaukopis-Athena:hgcase d$ touch foo.txt
Glaukopis-Athena:hgcase d$ hg st
? foo.txt
Glaukopis-Athena:hgcase d$ hg add foo.txt
Glaukopis-Athena:hgcase d$ hg commit -m "foo"
Glaukopis-Athena:hgcase d$ hg rm foo.txt
Glaukopis-Athena:hgcase d$ touch FOO.txt