Skip to content

Instantly share code, notes, and snippets.

View twe4ked's full-sized avatar
🐦
just setting up my twttr

Odin twe4ked

🐦
just setting up my twttr
View GitHub Profile
@ghoseb
ghoseb / factorial.py
Created November 14, 2008 18:58
The evolution of a Python Programmer
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@machu
machu / oauth-sample.rb
Created August 19, 2009 03:18
OAuth Consumer Example with Sinatra: http://www.machu.jp/diary/20090818.html#p01
require 'rubygems'
require 'sinatra'
require 'oauth'
require 'twitter'
helpers do
include Rack::Utils
alias_method :h, :escape_html
end
# Rack::SimpleServer
#
# a small rack app that acts like a basic HTTP server
# github.com/chendo
#
# Options:
# * :root => directory to expose
# e.g., use Rack::SimpleServer, :root => 'pub'
module Rack
@jasoncodes
jasoncodes / disable_mass_assignment.rb
Created August 17, 2010 09:52
Noisy protected attributes (mass-assignment security)
ActiveRecord::Base.send(:attr_accessible, nil)
@stuart
stuart / ABNCheck.rb
Created February 14, 2011 06:20
Check a string to see if it is a valid Australian Business Number
# Algorithm taken from ATO website.
def valid_abn?(abn)
WEIGHTS = [10,1,3,5,7,9,11,13,15,17,19]
tmpabn = abn.split("").map{|c| c.to_i}
tmpabn[0] = tmpabn[0] - 1
checksum = (0..10).inject(0) do |sum, i|
sum + (tmpabn[i].to_i * WEIGHTS[i])
end
return (checksum % 89) == 0
end
:+1:
:-1:
:airplane:
:art:
:bear:
:beer:
:bike:
:bomb:
:book:
:bulb:
@metaskills
metaskills / wait_until.rb
Last active May 2, 2024 01:51
Never sleep() using Capybara!
# WAIT! Do consider that `wait` may not be needed. This article describes
# that reasoning. Please read it and make informed decisions.
# https://www.varvet.com/blog/why-wait_until-was-removed-from-capybara/
# Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
describe 'Modal' do
should 'display login errors' do
visit root_path
@jasoncodes
jasoncodes / _form.html.haml
Created October 18, 2011 05:42
Using ActiveRecord optimistic locking with Inherited Resources
/ ...
- f.inputs do
= f.hidden_field :lock_version
/ ...
module ActiveModel
module MassAssignmentSecurity
module Sanitizer
protected
def warn!(attrs)
raise "Can't mass-assign protected attributes: #{attrs.join(', ')}"
end
end
end
end
@twe4ked
twe4ked / input.scss
Created December 5, 2011 06:27
FREE! Sass (SCSS) mixin for including retina images (useful when developing for iOS).
@mixin background-image-retina($file, $type, $width, $height) {
background-image: url($file + '.' + $type);
@media (-webkit-min-device-pixel-ratio: 2), (-moz-min-device-pixel-ratio: 2) {
& {
background-image: url($file + '@2x.' + $type);
-webkit-background-size: $width $height;
}
}
}