Skip to content

Instantly share code, notes, and snippets.

Troels Knak-Nielsen troelskn

Block or report user

Report or block troelskn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View attr_initializer.rb
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 = {})
View install_gems
#!/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
View logview.sh
#!/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 ]
View svn-diff.sh
#!/bin/bash
svn diff "$@" | source-highlight --out-format=esc --src-lang=diff
View svn-last.sh
#!/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
View autotest.sh
#!/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
View frep.sh
#!/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
View gist:148380
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);
View git-export
#!/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
View gist:167232
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
You can’t perform that action at this time.