Skip to content

Instantly share code, notes, and snippets.

View sideshowcoder's full-sized avatar
💭
🐱

Philipp Fehre sideshowcoder

💭
🐱
View GitHub Profile
class A
# Allow read access to var
attr_reader :var
# Set the INSTANCE variable var
def set
@var = "I am an instance variable"
end
# Print the LOCAL variable
var ||= "I'm a local variable"
@sideshowcoder
sideshowcoder / factory_1_to_many.rb
Created October 25, 2010 23:57
1 to many factory model
Factory.define :coffeeshop do |s|
s.sequence(:location) { |n| "town#{n}"}
end
Factory.define :coffee do |c|
c.sequence(:name) { |n| "coffee#{n}"}
c.tried false
c.association :coffeeshop
end
@sideshowcoder
sideshowcoder / render_action_call.rb
Created November 4, 2010 00:32
render :action => "new" does not call method new
def new
@a = A.new
@b = @a.b
end
def create
@a = A.new(params[:a])
@a.b_id = B.find(params[:b_id]).id
if @a.save
redirect_to(@a.b)
@sideshowcoder
sideshowcoder / render_action_call_working.rb
Created November 4, 2010 00:37
ender :action => "new" does not call method new so all variables must be set in create
def new
@a = A.new
@b = @a.b
end
def create
@a = A.new(params[:a])
@a.b_id = B.find(params[:b_id]).id
@b = @a.b
if @a.save
@sideshowcoder
sideshowcoder / font-embedding
Created November 15, 2010 22:36
Embedding fonts in CSS
@font-face {
font-family: 'Impact Label Regular';
src: url(http://fonts.sideshowcoder.com/fonts/impact_label/Impact_label-webfont.eot);
src: local('Impact Label Regular'),
url(http://fonts.sideshowcoder.com/fonts/impact_label/Impact_label-webfont.ttf) format('truetype'),
url(http://fonts.sideshowcoder.com/fonts/impact_label/Impact_label-webfont.svg#font) format('svg');
}
@sideshowcoder
sideshowcoder / nginx-font-serving
Created November 15, 2010 22:45
Nginx header write for serving fonts to firefox cross domain
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
@sideshowcoder
sideshowcoder / pack.js
Created December 9, 2010 16:43
Pack an Array to a Buffer following given format string
/* Extend Array to allow packing to Buffer
*
* Inspired by ruby array pack method
*
* Takes a format fmt and walks the array
* C = Element is interpreted as ASCII character (unsigned char)
* a = Element is interpreted as ASCII string
* n = Element is interpreted as Short generating a 2 octets
*
* Just for the hack of it ;)
@sideshowcoder
sideshowcoder / rename.sh
Created July 25, 2011 14:14
_1 replace string in filename for all files in folder
#!/bin/bash
FILES=$(ls *.tif)
for f in $FILES; do
NN=`echo $f | sed -e"s/\_1\./\_gfp\./"`
mv $f $NN
done
@sideshowcoder
sideshowcoder / titranslationfind
Created August 5, 2011 18:17
quick find all translateable strings in titanium project
find ./ -name "*.js" -exec cat '{}' \; | awk 'match($0,/L\(.+\)/) { print substr($0,RSTART+3,RLENGTH-5) }' | awk 'split($0, M, /\)/) { print M[1] }' | sed 's/\"//g' | sed "s/\'//g" | sort | uniq