Skip to content

Instantly share code, notes, and snippets.

View troelskn's full-sized avatar

Troels Knak-Nielsen troelskn

View GitHub Profile
@troelskn
troelskn / attr_initializer.rb
Created June 3, 2009 15:05
attr_initializer
class Class
# Adds a initialize method, which takes attributes as a hash
# Optionally call with symbol-names, to additionally create attribute accessors with `attr_accessor`
def attr_initializer(*args)
attr_accessor *args unless args.empty?
module_eval <<-END
def initialize(attributes = {})
initialize_attributes(attributes)
end
def initialize_attributes(attributes = {})
#!/usr/bin/env ruby
def parse_missing_required(input)
matches = input.match(/Missing these required gems:([\s\S]*)You're running:/)
matches[1].strip.split("\n").map do |line|
m = line.match(/^\s*(\S+)\s+(\S+\s+[0-9.]+)/)
p line if m.nil?
{:name => m[1], :version => m[2]}
end
end
#!/bin/bash
LINE_COLOR=`echo -en '\e[92m'`
LINE_COLOR_RESET=`echo -en '\e[00m'`
MATCH_COLOR=`echo -en '\e[1m\e[33m'`
MATCH_COLOR_RESET=`echo -en '\e[22m\e[92m'`
PATTERN=""
if [ $# = 0 ]
#!/bin/bash
svn diff "$@" | source-highlight --out-format=esc --src-lang=diff
#!/bin/bash
TARGET=$1
SVNROOT=`svn info | grep -h 'Repository Root: .*' | sed 's/Repository Root: //g'`
REVISION=`svn log --limit 1 --quiet $TARGET | grep -oh '^r.*' | sed 's/r\([0-9]*\).*/\1/g'`
svn log --limit 1 $TARGET
svn diff -c $REVISION $SVNROOT | source-highlight --out-format=esc --src-lang=diff
#!/usr/bin/env sh
print_usage() {
printf "Usage: %s [-t=TESTFILE] [-w=WATCHDIR]\n" $(basename $0)
echo " TESTFILE Command to run test"
echo " WATCHDIR Dir to watch for changes"
exit 2
}
# you need these dependencies:
# sudo apt-get install inotify-tools
#!/usr/bin/env bash
# find and replace by regexp in many files
PRUNE=""
REPLACE=""
print_usage() {
echo "USAGE: $(basename $0) [--prune EXTENSIONS] [--replace REPLACE] SEARCH"
echo " EXTENSIONS Comma separated list of file extensions to ignore"
exit 1
}
while true
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);
#!/bin/sh
[ $# -eq 2 ] || echo "USAGE $0 REPOSITORY DESTINATION" && exit 1
REPOSITORY=$1
DESTINATION=$2
TMPNAME="/tmp/$(basename $REPOSITORY).$$"
git clone $REPOSITORY $TMPNAME
rm -rf $TMPNAME/.git
mkdir -p $DESTINATION
cp -r $TMPNAME/* $DESTINATION
rm -rf $TMPNAME
require 'uri'
require 'cgi'
require 'net/https'
cert_file = feed_source.certificate_absolute_path
raise "Cert file required" if cert_file.nil? || !(File.exists?(cert_file) && !File.directory?(cert_file))
request = Net::HTTP.new(feed_source.url, 443)
request.use_ssl = true