Skip to content

Instantly share code, notes, and snippets.

View laktek's full-sized avatar

Lakshan Perera laktek

View GitHub Profile
link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }}, { :class => "fine" })
#Currently renders:
<a class="fine" href="#" onclick="new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;">Remote outauthor</a>
#suggested view render:
<a class="fine" data-rails-remote="true" href="http://www.example.com/whatnot">Remote outauthor</a>
#Method implemented by jquery.rails.js helper
$(a["data-rails-remote=true"]).($.ajax({
@laktek
laktek / httpdump
Created April 4, 2009 01:53 — forked from peterc/httpdump
# Monitor HTTP requests being made from your machine with a one-liner..
# Replace "en1" below with your network interface's name (usually en0 or en1)
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
# OR.. to be able to use as "httpdump" from anywhere, drop this into ~/.bash_profile:
# (again replace "en1" with correct network interface name)
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*""
# All the above tested only on OS X.
function parse_git_dirty {
git diff --quiet HEAD &>/dev/null
[[ $? == 1 ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\u@\h \[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$ '
# bootstrapper.rb
# Rails Bootstrapper using rails template
# Based on Extended Bort -http://github.com/laktek/extended-bort/tree/master
# Ideal to use when building a comprehensive web app
# Uses Braid to track remote repos.
# by Lakshan Perera
# Use Braid to track remote git or svn repos.
def braid(command, repo, options={})
other_params = ""
*sponsor.txt* For Vim version 7.1. Last change: 2007 Jan 05
VIM REFERENCE MANUAL by Bram Moolenaar
SPONSOR VIM DEVELOPMENT *sponsor*
Fixing bugs and adding new features takes a lot of time and effort. To show
@laktek
laktek / new_state_machine.rb
Created June 17, 2009 22:41
Vending Machine with multiple beverages (using State Pattern and a Singleton class)
require 'singleton'
class State
attr_accessor :machine
STATES = {:ready => "Ready", :listen => "Listen", :processing => "Processing"}
def initialize(machine)
@machine = machine
end
require 'singleton'
class State
attr_accessor :machine
STATES = {:ready => "Ready", :listen => "Listen", :processing => "Processing"}
def initialize(machine)
@machine = machine
end
class Message
attr_accessor :body
def initialize
@api_version = 1
@api_format = 1
@message_type = 1
@source_id = 64071
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
module Message
class AbstractMessage
attr_accessor :body, :api_version, :api_format, :message_type, :source_id, :destination_id, :checksum
def initialize
@api_version = 1
@api_format = 1
@message_type = 1