Skip to content

Instantly share code, notes, and snippets.

@sathish316
sathish316 / guess_my_number
Created Nov 29, 2010
Binary search guessing game from Land of Lisp book
View guess_my_number
(defparameter *small* 1)
(defparameter *big* 100)
(defun guess-my-number ()
(ash (+ *small* *big*) -1))
(defun smaller ()
(setf *big* (1- (guess-my-number)))
(guess-my-number))
View gist:722109
class Array
def car
first
end
def cdr
self[1..-1]
end
def method_missing(method_id)
View emacscheatsheet
emacs shortcuts
C-x C-c quit
C-v next screen
M-v previous screen
C-l move cursor to center
C-f forward char
C-b backward char
C-p previous line
C-n next line
View .gitconfig
[alias]
st = status
ci = commit
br = branch
co = checkout
df = diff
lg = log -p
rpull = pull --rebase
[user]
name = Sathish
@sathish316
sathish316 / ai-class.py
Created Dec 7, 2011 — forked from sumodx/ai-class.py
Download lecture videos of ai-class, with basic resume support
View ai-class.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Deepak.G.R."
__credits__ = "Sumod Hajela"
__license__ = 'Public Domain'
"""
usage:
Go to command line and type
@sathish316
sathish316 / ycombinator.ss
Created Jan 23, 2012
Y combinator (Little Schemer)
View ycombinator.ss
; function to find the length of a list
(define length
(lambda (l)
(cond
((null? l) 0)
(else (+ 1 (length (cdr l)))))))
; function that recurs infinitely
(define eternity
(lambda (l)
@sathish316
sathish316 / alphametric_solver.rb
Created Jan 29, 2012
Alphametric solver for equations like SEND + MORE = MONEY (Golf version)
View alphametric_solver.rb
def s(e)
c=e.scan(/\w{1}/).uniq
d=('0'..'9').to_a
d.permutation(c.size).each{|p|o=c.zip(p).inject(e){|e,d|e.gsub(*d)};return o if o !~/\b0/ && eval(o)}
end
puts s("SEND + MORE == MONEY")
@sathish316
sathish316 / gol.rb
Created Feb 9, 2012
Game of life golf
View gol.rb
d=[-1,0,1] n=->(w,i,j){(d.product(d)-[[0,0]]).map{|x,y|w[[i+x,j+y]]}.count(true)} t=->(w){Hash[w.map{|k,v|c=n.(w,*k);[k,(v&&c==2)||c==3]}]}
@sathish316
sathish316 / golbits.rb
Created May 17, 2012
Game of life bit twiddling
View golbits.rb
=begin
........ 0x00
........ 0x00
..XX.... 0x30
..XX.... 0x30
....XX.. 0xC0
....XX.. 0xC0
........ 0x00
........ 0x00
=end
View csv.rb
def show
@results = Foo.all
respond_to do |format|
format.csv { render_csv "report"}
end
end
private
def render_csv(filename = nil)