Skip to content

Instantly share code, notes, and snippets.

@fj
fj / bf.rb
Created March 18, 2014 18:12
Brainfuck interpreter in Ruby
$_=$$/$$;@_=$_+$_;$-_=$_-@_
$__=->_{_==[]||_==''?$.:$_+$__[_[$_..$-_]]}
@__=->_,&__{_==[]?[]:[__[_[$.]]]+@__[_[$_..$-_],&__]}
$_____=->_{@__[[*_],&->__{__[$.]}]}
@_____=->_{@__[[*_],&->__{__[$-_]}]}
$______=->_{___,______=$_____[_],@_____[_];_____=$__[___];____={};__=$.;(_=->{
____[______[__]]=___[__];(__+=$_)==_____ ?____:_[]})[]}
@______=->_,__{_=[*_]+[*__];____=$__[_];___={};__=$.;(_____=->{
___[_[__][$.]]=_[__][$_];(__+=$_)==____ ?___:_____[]})[]}
$_______=->_{$___=[];@___=$__[_];__=___=____=$.;$____,@____={},[]
@fj
fj / gist:9691518
Last active August 29, 2015 13:57
"Your Mission", by Ellen M. H. Gates (1865)
If you cannot, on the ocean, sail among the swiftest fleet,
Rocking on the highest billows, laughing at the storms you meet,
You can stand among the sailors, anchored yet within the bay,
You can lend a hand to help them, as they launch their boats away.
If you are too weak to journey up the mountain steep and high,
You can stand within the valley, while the multitudes go by;
You can chant in happy measure, as they slowly pass along;
Though they may forget the singer, they will not forget the song.
def outer(&b)
foo = 1
block.call
end
def inner(v)
puts foo + v
end
# Is there a way to make 'foo' available in the scope of `inner`?
def with_model(m, &block)
w = Object.new
w.define_singleton_method :model do
m
end
w.instance_eval &block
end
def property(name)
puts model.to_s + name.to_s
require 'spec/environment_spec_helper'
describe 'UsersController' do
describe 'GET /new' do
it { expect(:get => '/users/new').to be_routable }
it {
get '/users/new'
expect(last_response.status).to eq 200
}
@fj
fj / game.rb
Created July 10, 2014 05:33
My work on the Uncle Bob bowling kata.
class Game
def roll(*pins)
(@rolls ||= []).push *pins
end
def score
scores.inject(:+)
end
def scores
@fj
fj / gist:62953162c079eeca30bb
Created August 1, 2014 22:40
star-ruler-2 dump
Loaded in 1.3 seconds
/home/polytope/.local/share/Steam/SteamApps/common/Star Ruler 2/scripts/server/empire.as:
Compiling void markDesignObsolete(Player&inout, const Design@, bool)
Error (302:5): Expression must be of boolean type
ERROR: Failed to build module 'empire' in manager 'server' (code -1).
ERROR: 'cheats': Cannot import function 'void setInstantColonize(bool)': module 'planets.SurfaceComponent' does not exist.
ERROR: 'empire_ai.EmpireAI': Cannot import function 'AIController@ createBasicAI()': module 'empire_ai.BasicAI' does not exist.
ERROR: 'orbitals': Cannot import function 'SystemDesc@ getSystem(Region@)': module 'game_start' does not exist.
ERROR: 'system_pathing': Cannot import function 'SystemDesc@ getSystem(uint)': module 'game_start' does not exist.
ERROR: 'system_pathing': Cannot import function 'SystemDesc@ getSystem(Region@)': module 'game_start' does not exist.
@fj
fj / gist:2900f29c6dc77d0e7c00
Last active August 29, 2015 14:07 — forked from cammckinnon/gist:2369233
fizzbuzz-in-brainfuck
[-]>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<<<<<
>>>>>>
[-]>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<<<<<
>>>>>>
>
[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@fj
fj / time.rb
Created October 31, 2014 17:51
perplexing round-trip Time instance behavior
t1 = Time.now
# => 2014-10-31 13:48:12 -0400
t2 = Time.at(t1.to_i)
# => 2014-10-31 13:48:12 -0400
t1.to_a
# => [12, 48, 13, 31, 10, 2014, 5, 304, true, "EDT"]
t2.to_a
@fj
fj / .rubocop.yml
Created November 5, 2014 15:36
UpHex's Rubocop and Rakefile
Metrics/LineLength:
Max: 125