Skip to content

Instantly share code, notes, and snippets.

burningTyger

Block or report user

Report or block burningTyger

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 gist:449848
require "matrix"
#First, you construct an adjacency matrix. An adjacency matrix is just a matrix of what is linking to what.
#[0, 1, 1, 1, 1, 0, 1]
#[1, 0, 0, 0, 0, 0, 0]
#[1, 1, 0, 0, 0, 0, 0]
#[0, 1, 1, 0, 1, 0, 0]
#[1, 0, 1, 1, 0, 1, 0]
#[1, 0, 0, 0, 1, 0, 0]
View partials.rb
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
View mixin_models.rb
module Food
def self.included(model)
model.property :id, Serial
model.property :price, Integer, :min => 0 # builtin validation works just fine
model.property :calories, Integer, :min => 0
model.before(:valid?, :custom_validation)
end
def custom_validation
View sinatra_patch.rb
module Sinatra
class Base
def call!(env)
@env = env
@request = Request.new(env)
@response = Response.new
@params = indifferent_params(@request.params)
force_encoding(@params)
@burningTyger
burningTyger / BASH prompt
Created Jan 7, 2011
git and rvm enabled BASH prompt
View BASH prompt
#This is my personal prompt. Script taken from
#http://tammersaleh.com/posts/a-better-rvm-bash-prompt
function __git_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo "!"
}
function __git_branch {
__git_ps1 " %s"
View app.rb
require 'rubygems'
require 'haml'
require 'sinatra'
require 'sinatra/flash'
require 'file_uploader'
enable :sessions
get '/' do
haml :index
View moodle.js
register({
name: 'moodle.domain.com',
url: 'http://moodle.domain.com/',
icon: 'http://moodle.domain.com/theme/mytheme/favicon.ico',
domains: [ 'moodle.domain.com' ],
sessionCookieNames: [ 'MoodleSession', 'MoodleSessionTest' ],
identifyUser: function() {
var site = this.httpGet('http://moodle.domain.com/user/view.php');
this.userName = site.body.querySelector('div.logininfo a').text;
View git.sh
# To just pull changes from Github, forcing Git to use your local changes for any conflicts:
git pull --strategy=ours origin master
# To completely update each of your Git repositories in one command (run this inside each repository):
git add . && git commit -m "Updating to current working version" && git pull --strategy=ours origin master && git push origin master
@burningTyger
burningTyger / gist:1032625
Created Jun 18, 2011
rbx bug in IO#lineno
View gist:1032625
counter={}
File.open('lines.txt', 'r') do |f|
f.each_line do |l|
counter[f.lineno] = l
end
end
counter.each_pair {|k,v| puts "#{k}: #{v}"}
#where lines.txt is
@burningTyger
burningTyger / sparkle.zsh-theme
Created Jul 20, 2011
oh-my-zsh sparkle theme
View sparkle.zsh-theme
# This theme focuses on the current Ruby and git status/branch
PROMPT='$fg[yellow]$(rvm-prompt i v g) $fg[white]%n@%m:%~$(git_prompt_info)$reset_color $ '
# git theming
ZSH_THEME_GIT_PROMPT_PREFIX="$fg[yellow] "
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="$fg[red]!"
You can’t perform that action at this time.