Skip to content

Instantly share code, notes, and snippets.

@losvedir
losvedir / rspec_magic.rb
Last active Dec 25, 2015
Exploration into how Rspec could provide some of its nice syntactical features
View rspec_magic.rb
require 'ostruct'
class Object
def expect(value)
@expector = Expector.new(value)
end
def eq(val)
[:==, val]
end
View 20130320032255_create_organizations.rb
class CreateOrganizations < ActiveRecord::Migration
def change
create_table :organizations do |t|
t.string :name
t.boolean :has_octocats
t.timestamps
end
end
end
@losvedir
losvedir / Rails SQL stuff
Created Dec 3, 2012
Rails 3 ActiveRelation counting, grouping, sorting, and limiting
View Rails SQL stuff
Model.joins(:relation)
.merge(Relation.scope)
.count(group: 'column or postgres function',
order: 'count_all DESC',
limit: 10
)
# Note: the count_all is the 'AS' variable ActiveRelation makes for you.
@losvedir
losvedir / rspec-syntax-cheat-sheet.rb
Created May 11, 2012 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
View rspec-syntax-cheat-sheet.rb
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@losvedir
losvedir / 1 - NEW _delivery.html.erb
Created Mar 22, 2012
Convert delivery methods from radio buttons to select options
View 1 - NEW _delivery.html.erb
<%= form.select :shipping_method, shipping_methods_for_select(@order) %>
@losvedir
losvedir / 1 - NEW _delivery.html.erb
Created Mar 22, 2012
Convert delivery methods from radio buttons to select options
View 1 - NEW _delivery.html.erb
<%= form.select :shipping_method, shipping_methods_for_select(@order) %>
@losvedir
losvedir / Vinegar.txt
Created Feb 15, 2011
Breaking Wilhelm von Hackensplat's Vinegar cipher
View Vinegar.txt
From HN thread here: http://news.ycombinator.com/item?id=2222228
Challenge posed here: http://blog.hackensplat.com/2011/02/vinegar.html
It seems the cipher is an application of viginere four times. So, if the original
17 character key is x1 x2 y1 y2 y3 z1 z2 z3 z4 z5 t1 t2 t3 t4 t5 t6 t7, and the
original text is C1 C2 C3 C4, then the ciphertext we're given of IWY SEIX....
can be thought of as follows:
I = (C1+x1+y1+z1+t1)
W = (C2+x2+y2+z2+t2)
@losvedir
losvedir / gist:661564
Created Nov 3, 2010
Cracker Barrel Triangle Peg Jumping Game Solver
View gist:661564
/* Solves one of those triangle shaped peg jumping puzzles.
You begin with a board composed of n rows, where the i-th
row contains i columns. e.g.:
X
X X
X X X
The board begins with pegs in all holes but one. A peg can
jump over another peg if it can land in a hole on the other
side. The jumped peg is removed. The goal is to finish with
a single peg remaining.
View gist:605558
#include <stdio.h>
main() {
int n[] = {1819043144, 663919}, i;
char *c;
c = (char*)n;
printf("%s", c);