-
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
#!/bin/sh | |
tr -Cd '][.,<>+-'|sed 's/\./putchar(*p);/g;s/,/*p=getchar();/g;s/[+-]/&&*p;/g;s/[<>]/&&p;/g;s/\[/while(*p){/g;y/]<>/}-+/;s/^/main(){int a[30000];int *p=a;/;s/$/}/'|cc -xc - |
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
(?xi) | |
\A | |
# unreserved: [a-z0-9\-._~] | |
# sub-delims: [!$&'()*+,;=] | |
# pct-encoded: %[0-9a-f]{2} | |
# dec-octet: (?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]) | |
# pchar: (?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2}) | |
# h16: [0-9a-f]{1,4} | |
# ls32: (?:[0-9a-f]{1,4}:[0-9a-f]{4}| | |
# (?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]) |
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
# 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
(define L (lambda (a) (lambda (b) (lambda (c) (lambda (d) (lambda (e) (lambda (f) (lambda (g) (lambda (h) (lambda (i) (lambda (j) (lambda (k) (lambda (l) (lambda (m) (lambda (n) (lambda (o) (lambda (q) (lambda (p) (lambda (s) (lambda (t) (lambda (u) (lambda (v) (lambda (w) (lambda (x) (lambda (y) (lambda (z) (lambda (r) (r ((((((((((((((((((((((((((t h) i) s) i) s) a) f) i) x) e) d) p) o) i) n) t) c) o) m) b) i) n) a) t) o) r))))))))))))))))))))))))))))) | |
(define Yk (((((((((((((((((((((((((L L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L)) | |
(define (factorial c) | |
(lambda (n) | |
(if (= n 0) | |
1 | |
(* n (c (- n 1)))))) |