tags: markdown cheatsheet help author: admin protected: admin
{:.no_toc}
- toc {:toc}
#!/usr/bin/env ruby | |
require 'mail' | |
Mail.defaults do | |
delivery_method :smtp, { :address => "smtp.mandrillapp.com", | |
:port => 587, | |
:user_name => "YOUR_MANDRILL_USERNAME", | |
:password => "YOUR_API_KEY", | |
:authentication => 'plain', |
def rgb(r, g, b)16+(r.to_i*36)+(g.to_i*6)+b.to_i end | |
def colorize(s, fg, bg = nil) "#{fg ? "\x1b[38;5;#{fg}m" : ''}#{bg ? "\x1b[48;5;#{bg}m" : ''}#{s}\x1b[0m" end | |
def rainbow(n)f,w,o=5.0/n,3,3; (0...n).map{|i| rgb(Math.sin(f*i+0)*o+w, Math.sin(f*i+2)*o+w, Math.sin(f*i+4)*o+w)} end | |
def display(board, goal=2048) | |
@palette ||= rainbow(Math.log2(goal)) | |
puts board.map{|r| r.map{|c| colorize((c==0 ? ?. : c).to_s.center(6), @palette[Math.log2(c+1)])}.join}.join("\n\n") | |
end | |
def compress(board, direction) | |
t=->(a){z=0;a.reduce([]){|s,e| z+=e==s[-1]? (s[-1]+=e;1): e>0? (s<<e;0): 1;s}+Array.new(z,0)} # trivial case: 1D array to the left |
import java.io.*; | |
DataInputStream dis; | |
void setup() | |
{ | |
size(256, 256); | |
try { | |
dis = new DataInputStream(new FileInputStream("/home/robbe/tmp/howtodrawmushrooms.8s.raw")); // 192khz, 8 bit signed, stereo PCM |
<body><script> | |
/* SET `$appurl` as argument to the IIFE | |
to load any javascript (localstorage size limit 5mb) | |
The first page visit will load the whole script, follow-up visits | |
load the cached script right away and if a new version is available, | |
offer to update the app now or later. | |
(The caching only works if the server sends `header.etag`) | |
I welcome suggestions/questions/discussions - just drop me a message :-) | |
http://twitter.com/serapath |
begin | |
['oily_png', 'pp'].each do |g| | |
require g | |
end | |
rescue LoadError => e | |
puts "Could not load '#{e}'"; exit | |
end | |
class Hough | |
Convert = "/usr/local/bin/convert" |
#!/usr/bin/env ruby | |
DATA.flock(File::LOCK_EX | File::LOCK_NB) or abort "Already running." | |
Process.daemon(true) | |
def active_window_info | |
Hash[`xprop -id $(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}')` | |
.scan(/^WM_(NAME|CLASS).*? = "(.*?)"(, "|$)/) | |
.map{|e| e.first.downcase!; e[0..-2]}] |
# $ grep '^###' ruby_nuggets.rb | |
# if you just want all headlines | |
### multiple heredoc goodness | |
head,body = <<END_HEAD,<<END_BODY | |
this is the head | |
yea still head | |
END_HEAD | |
and now some body | |
it is #{Time.now} now |
/* An HTML template in 180 bytes (minified) | |
Features: Escapes HTML, accepts either strings or functions as values, and that's all (it doesn't handle looping). | |
Usage: | |
OneEightyT( | |
"<h1>{name}</h1><div>{content} @ {currentTime}</div>", | |
{ | |
name: "Stella", |
function foo(args) { | |
var i, j, k; | |
// ... | |
// j acquires some interesting value | |
// Who called foo when j took this interesting value? | |
// | |
var e = new Error('dummy'); | |
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '') | |
.replace(/^\s+at\s+/gm, '') |