Skip to content

Instantly share code, notes, and snippets.

View zeroeth's full-sized avatar
🤖
🐱 🤖 🐱 🤖

[0] zeroeth

🤖
🐱 🤖 🐱 🤖
View GitHub Profile
Scenario with magic
Given I use vim and tabular
When I cast a magic spell
Then I should see the following cukes:
| Latin | English |
| Cucumis sativus | Cucumber |
| Cucumis anguria | Burr Gherkin |
io = File.open(...)
len = io.read(2).unpack("v")[0]
name = io.read(len)
width, height = io.read(8).unpack("VV")
puts "Rectangle #{name} is #{width} x #{height}"
class Rectangle < BinData::Record
endian :little
uint16 :len
string :name, :read_length => :len
uint32 :width
uint32 :height
end
io = File.open(...)
r = Rectangle.read(io)
class Names < BinData::Record
# non terminated fixed size string
string :fixed_size_name, :length => 6
# string followed by a \0
stringz :zero_terminated_name
# size stored before string
int8 :name_length
string :data, :read_length => :name_length
class MyItems
# This will read in only 3 ints
array :fixed_length_array, :initial_length => 3 do
uint8
end
# This will read in each unit and pass it to the lambda until its value is 5
array :variable_length_array, :read_until => lambda { element != 5 } do
uint8
end
# Parse an NBT file (from Minecraft's map data)
class Compound < BinData::Record; end
class TagEnd < BinData::Record; end
class TagString < BinData::Record; end
class Payload < BinData::Record
int8 :tag_type
# This is very much like dealing with single table inheritance in ActiveRecord.
body {
color: #eeeeec;
background-color: #888a85;
}
#header {
color: #eeeeec;
background-color: #3465a4;
padding: 16px;
margin: 16px 0;
@zeroeth
zeroeth / branch_databases.yml
Created March 16, 2011 22:54
use your git branch and some regex rules to determine which db to use
# This file reads in the current git branch and bases your database name on the rules you setup here
# if no output is given, use the capture from the select.
# if output given, lambda may access the matcher regex object, or just return a string
# match multiple branches, all share a db.
shared_db_for_all_cats:
select: ^(cat)
# match multiple, individual db
db_for_each_cat:
source 'http://rubygems.org'
gem 'carmen'
gem 'carrierwave'
gem 'decent_exposure'
gem 'devise'
gem 'fabrication'
gem 'ffaker'
gem 'fog'
gem 'haml-rails'
# Paperclip compliant class for uploading files through URL
# Simplified version of http://github.com/chris/paperclip_url_support
require "open-uri"
module Paperclip
class UrlTempfile < Tempfile
attr :content_type
def initialize(url)