-
command interface
most commands should be web services; all commands should use the same interface. like a Rack application, but for commands!
for instance, i could define a WebServiceCommand class that would just take the url of an oblique-ish service and execute on it;
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
# Copyright David Kendal, 2013 | |
# You may redistribute this code, modified or unmodified, provided that this article is preserved in its entirety. | |
# Like all software, and information generally, this work is without warranty. | |
import inspect | |
# "if isscript():" is "if __name__ is '__main__':" | |
def isscript(frames=1): | |
callers = inspect.getouterframes(inspect.currentframe()) | |
return callers[frames][0].f_globals['__name__'] == '__main__' |
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
exec tcpclient irc.freenode.net 6667 sh <<EOF | |
echo "NICK topicsed" >&7 | |
echo "USER topicsed +iw swtopic :topicsed" >&7 | |
echo "JOIN #swhack" >&7 | |
cat <&6 | sed -n '/TOPIC #swhack :.*/ s/.*:\(.*\).*/\1/p' | |
EOF |
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
# usage: | |
# | |
# case compare(2,3) | |
# when :> | |
# puts "greater" | |
# when :< | |
# puts "less" | |
# when :== | |
# puts "same" | |
# end |
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 dectime | |
t = Time.now | |
daysec = t.hour * 3600 + t.min * 60 + t.sec | |
h = (daysec / 8640.0).floor | |
m = ((daysec / 86.4) % 100).floor | |
s = ((daysec / 0.864) % 100).floor | |
[h,m,s] | |
end |
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
import requests | |
import json | |
import sys | |
from collections import deque | |
from concurrent.futures import ThreadPoolExecutor as Pool | |
from datetime import datetime | |
from os import mkdir | |
from os.path import isdir | |
def debug(*args, **kwargs): |
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
# Why? Why not! | |
def cfhash string | |
result = string.length | |
max = 2 ** 32 | |
string.each_codepoint do |cp| | |
result = ((result * 257) % max) + cp | |
end | |
return (result + (result << (string.length & 31))) % max | |
end |
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 'matrix' | |
require 'interpolator' | |
class Munsell | |
HUES = %w{R YR Y GY G BG B PB P RP}.map(&:to_sym) | |
INVHUES = %w{RY YG GB BP PR}.map(&:to_sym) | |
# from http://www.color.org/srgb.pdf | |
SRGBMAT = Matrix[[ 3.2406, -1.5372, -0.4986], |
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 |
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) |