This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros | |
# | |
# Optimized version which uses to_yaml for content creation and checks | |
# that models are ActiveRecord::Base models before trying to fetch | |
# them from database. | |
namespace :db do | |
namespace :fixtures do | |
desc 'Dumps all models into fixtures.' | |
task dump: :environment do | |
models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires ImageMagick | |
# Converting the source from JPEG to PNG - if necessary | |
convert my_src_image.jpg my_src_image.png | |
# Option A | |
# - Requires a temporary intermediate file | |
# - Drill more than 10 might result in poor results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# C implementation of Levenshtein text distance algorithm, uses RubyInline to call from within Ruby | |
# Wildly faster than the Text gem's Text::Levenshtein | |
# Example: | |
# l = Levenshtein.new | |
# l.distance 'hello', ' hello' | |
# => 1 | |
# Taken from http://www.benallfree.com/2008/10/05/finding-duplicate-text-with-ruby/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Net | |
class HTTP | |
alias_method '__initialize__', 'initialize' | |
def initialize(*args,&block) | |
__initialize__(*args, &block) | |
ensure | |
@debug_output = $stderr ### if ENV['HTTP_DEBUG'] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
require 'eventmachine' | |
require 'em-http-request' | |
EM.run do | |
class App < Sinatra::Base | |
helpers do | |
def wait_for(&block) | |
while block.call.nil? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gollum/frontend/app' | |
require 'digest/sha1' | |
class App < Precious::App | |
User = Struct.new(:name, :email, :password_hash, :can_write) | |
before { authenticate! } | |
before /^\/(edit|create|delete|livepreview|revert)/ do authorize_write! ; end | |
helpers do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import subprocess | |
def git(args, **kwargs): | |
environ = os.environ.copy() | |
if 'repo' in kwargs: | |
environ['GIT_DIR'] = kwargs['repo'] | |
if 'work' in kwargs: | |
environ['GIT_WORK_TREE'] = kwargs['work'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Note the use of env. This is because executables may not be placed in the same place on all systems. Notoriously, bsd (and thus mac osx) differs from linux. However, /usr/bin/env always exists in the same place, and it can tell you where other executables are. Thus, the above is good style for portability. | |
COMMIT_VERSION=$(git rev-parse --verify HEAD) | |
# You could also use backticks, but the $() syntax is generally more readable | |
# Convention is to put variables in uppercase in shell script | |
curl -k -u user:password \ | |
-d "to=lsolesen&msg=%22Intraface+build+failed%22&title=Intraface+build+failed&uri=https%3A%2F%2Fgithub.com%2Fintraface%2Fintraface.dk%2Fcommit%2F${COMMIT_VERSION}" \ | |
https://api.notifo.com/v1/send_notification > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
phpsh (c)2006 by Charlie Cheever and Dan Corson and Facebook, Inc. | |
type 'h' or 'help' to see instructions & features | |
New Feature: You can use the -c option to turn off coloring | |
php> var_dump(null > 10); | |
bool(false) | |
php> var_dump(null < 10); | |
bool(true) | |
php> var_dump(null == 10); | |
bool(false) | |
php> var_dump(null == null); |