This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; kind of a stupid implementation but with | |
(define-syntax define-macro | |
(er-macro-transformer | |
(lambda (exp rename compare) | |
(if (symbol? (cadr exp)) | |
(let ((name (cadr exp)) | |
(expndr (caddr exp)) | |
(-exp (gensym)) (-rename (gensym)) (-compare (gensym))) | |
`(define-syntax ,name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (ack m n) | |
(cond ((zero? m) (+ n 1)) | |
((and (> m 0) (zero? n)) (ack (- m 1) 1)) | |
((and (> m 0) (> n 0)) (ack (- m 1) (ack m (- n 1)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def djb2 str | |
hash = 5381 | |
str.each_byte do |b| | |
hash = (((hash << 5) + hash) + b) % (2 ** 32) | |
end | |
hash | |
end | |
def djb2a str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def txt2num str | |
letters = {'a' => 2, 'b' => 2, 'c' => 2, | |
'd' => 3, 'e' => 3, 'f' => 3, | |
'g' => 4, 'h' => 4, 'i' => 4, | |
'j' => 5, 'k' => 5, 'l' => 5, | |
'm' => 6, 'n' => 6, 'o' => 6, | |
'p' => 7, 'q' => 7, 'r' => 7, 's' => 7, | |
't' => 8, 'u' => 8, 'v' => 8, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
NUMS = [[], [], ['a', 'b', 'c'], ['d', 'e', 'f'], | |
['g', 'h', 'i'], ['j', 'k', 'l'], ['m', 'n', 'o'], | |
['p', 'q', 'r', 's'], ['t', 'u', 'v'], ['w', 'x', 'y', 'z']] | |
def num2txt str | |
ps = [] | |
str.each_char do |char| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'geoip' | |
require 'tzinfo' | |
geoip = GeoIP.new('GeoLiteCity.dat') | |
location = geoip.city ARGV[0] | |
if location.nil? | |
puts Time.now.utc.to_datetime.iso8601 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
%w{sinatra redcarpet erb}.map{|l|require l};include Redcarpet | |
md=Markdown.new Class.new(Render::HTML){def preprocess text;text.gsub /\[\[([\w-]+?)\]\]/,'[\1](/\1)';end},filter_html:1 | |
helpers{include ERB::Util};Dir.mkdir'w'unless Dir.exist?'w' | |
get('/'){redirect to'home'} | |
get('/:p'){f='w/'+params[:p];File.exist?(f)? "<h1>#{h params[:p]}</h1>#{md.render File.read f}<a href=\"/#{params[:p]}/edit\">edit</a>; last was #{File.mtime f}": redirect(to params[:p]+'/edit')} | |
get('/:p/edit'){"<h1>Edit #{h params[:p]}</h1><form method=post><textarea name=c>#{h File.read "w/#{params[:p]}" rescue()}</textarea><input type=submit></form>"} | |
post('/:p/edit'){File.write('w/'+params[:p],params[:c]);redirect to params[:p]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ciphertext, base64-encoded: | |
myitFUAbTS1M4VQTl3P3cWWoJt8xvv9mmIJbrd1vkPy0RLdwrpwp+r5KYUX5 | |
b8cHARXp1xknwstJnxZNr6f0lB1b+J7E+WW/e7rmuHDlkin+pJ/yYNn6s2Dh | |
YG3AWUs5dYGPFRsC7mpuTc4IJxLo6L/H0UKI8pSCVd0P11pxmshGeuEvFurm | |
3P0wyTr9kA4QVencMuv48rLz4SEFO4n5iYMkJ8YAgVHmbZzgvpGPrUTWCzPI | |
9YCfXoqVydFCCRlt6ZHmGUK65S+ZIod/JmrUKzw/zlSsgs2IGIbzuLlujzfC | |
cN6TUEuwy6rNkdke0ud8j4a9wER52CtnBY1eqohC5Dx5CGsZdg4cs3zrUG4r | |
LrSRhcdmyNxPrB5IhzezzVcw62nBbXJbQfPDKYq3xj02o5sBka4METYS1E4X | |
Z+h0yqZy+6XhjX8IsveLQ7m9vNGY8E4+tWWR8bE5Hu7eT8VmjlRU8UjZatz5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; <sbp> this is why lisp engineers aren't allowed to pilot submarines | |
(setq *all-conses* (make-array 100000)) | |
(dotimes (ii 100000) (setf (aref *all-conses* ii) (cons nil nil))) | |
(setq *conses-index* 0) | |
(defun cons (hd tl) | |
(let ((the-cons (aref *all-conses* *conses-index*))) | |
(setq *conses-index* (1+ *conses-index*)) | |
(setf (car the-cons) hd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hpricot' | |
require 'diff/lcs' | |
class HTMLDiff | |
def self.diff a, b | |
self.new(a, b).compare | |
end | |
def initialize a, b |