Skip to content

Instantly share code, notes, and snippets.

View pachacamac's full-sized avatar
🌶️
Mmmmhmmmm

Marc pachacamac

🌶️
Mmmmhmmmm
  • Hacker/Founder
  • Germany, Berlin
View GitHub Profile
@albertico
albertico / mandrill-mail-example.rb
Last active August 29, 2015 13:56
Mandrill Example (Ruby)
#!/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',
@pachacamac
pachacamac / 2048.rb
Last active August 29, 2015 13:57
2048 game in concise but not golfed Ruby
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
@serapath
serapath / index.html
Last active September 23, 2015 16:16
App Loader with Update Manager
<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
@rondale-sc
rondale-sc / ruby-hough.rb
Created September 21, 2011 23:05
The hough transform in ruby. Only looks for straight black lines.
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"
@pachacamac
pachacamac / winspy.rb
Created October 21, 2012 20:27
Log what programs you're using
#!/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]}]
@pachacamac
pachacamac / ruby_nuggets.rb
Created October 21, 2012 19:36
Some very nice tricks and helpful magic in Ruby
# $ 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

tags: markdown cheatsheet help author: admin protected: admin

Markdown Cheatsheet

{:.no_toc}

  • toc {:toc}
/* 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",
@jay3sh
jay3sh / stack-trace-without-exception.js
Created August 20, 2011 10:33
print stack trace anywhere
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, '')