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
@pachacamac
pachacamac / rails_routes.js.erb
Created February 27, 2015 15:08
RailsRoutes.js.erb
var RailsRoutes = (function(){
return {
<% Hash[Rails.application.routes.routes.map{|e| ["#{e.name}_path", e.path.spec.to_s.gsub('(.:format)','')]}].each do |name, path| %>
<%= name %>: function(<%= path.scan(/:(\w+)/).map(&:first).join(', ') %>){return <%= "'"+path.gsub(/:(\w+)/){ "'+#{$1}+'" }+"'" %>;},
<% end %>
};
})();

server

avconv -f x11grab -r 25 -s 1920x1200 -i :0.0 -vcodec libx264 -tune zerolatency -f mpegts udp://127.0.0.1:1234

client

mplayer -benchmark udp://127.0.0.1:1234
@pachacamac
pachacamac / little_lambdas.rb
Created April 8, 2015 11:54
little lambdas - simple s-expressions and then some
# encoding: UTF-8
def evaluate(f)
return f unless [Array, Proc].include?(f.class)
f.map! &method(:evaluate)
begin
send(f[0],*f[1..-1])
rescue
f[1].send(f[0],*f[2..-1])
rescue
@pachacamac
pachacamac / captcha_solver.rb
Created May 12, 2015 02:07
solves a captcha for some site most of the time :)
def solve_captcha(image)
begin
require 'oily_png'
rescue LoadError
STDERR.puts 'Warning: Gem oily_png not found. Using chunky_png instead. This will be slow!'
require 'chunky_png'
end
img = ChunkyPNG::Image.from_file(image)
ps = Hash.new
img.width.times{|x| img.height.times{|y|
@pachacamac
pachacamac / parallel_map.rb
Last active August 29, 2015 14:22
Parallelize stuff in Ruby with a simple but cool addon to Enumerable!
module Enumerable
# inside the block you can use Thread.exit to stop this execution and Thread.exclusive{...} to synchronize stuff
def parallel_map
map{|x| Thread.new{ Thread.current[:result] = yield(x) } }.map{|t| t.join; t[:result]}
end
def parallel_map_in_chunks(chunk_size=8, debug=false, &block)
chunks = each_slice(chunk_size).each_with_index
chunks.map{|chunk,i|
puts "chunk #{i+1}/#{chunks.size}. chunk_size=#{chunk.size}" if debug
@pachacamac
pachacamac / rpi_streamer.sh
Last active August 29, 2015 14:23
stream live audio to RPI
#$!/bin/bash
USER=root
HOST=rpi
BUF=8192 #4096 #16384
(sleep 2 && \
parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | \
sox --buffer $BUF -t raw -r 44100 -e signed-integer -L -b 16 -c 2 - -t raw - -V0 | \
nc -O $BUF $HOST 44099) &
@pachacamac
pachacamac / myskeleton.css
Created June 20, 2015 18:53
skeleton with normalize and some extras
@import url(http://fonts.googleapis.com/css?family=Raleway);
/*normalize.css v3.0.2*/
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
body{margin:0}
article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}
audio,canvas,progress,video{display:inline-block;vertical-align:baseline}
audio:not([controls]){display:none;height:0}
[hidden],template{display:none}
@pachacamac
pachacamac / time_in_words.rb
Last active August 29, 2015 14:24
A pretty decent time_in_words method without any dependencies
def time_in_words(to, from=Time.now, opts={})
dist = (to.to_i - from.to_i).abs
prefix, appendix = from > to ? ['',opts[:appendix]||' ago'] : [opts[:prefix]||'in ', '']
raw = [['years',31557600],['months',2592000],['weeks',604800],['days',86400],['hours',3600],['minutes',60],['seconds',1]].map{|u,s|
c = (dist / s).floor
dist -= c * s
c == 0 ? nil : "#{c} #{c == 1 ? u[0...-1] : u}"
}.compact.join(' ')
"#{prefix}#{raw}#{appendix}"
end
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, '')
@pachacamac
pachacamac / gist:f3b1310b1bbb0bcf8746
Last active August 29, 2015 14:25 — forked from atcuno/gist:3425484ac5cce5298932
HowTo: Privacy & Security Conscious Browsing

The purpose of this "howto" is to document how browsing can be done in a privacy and security conscious manner. This information is compiled from a number of sources, which are referenced throughout the document, as well as my own experiences with the described technologies.

I welcome contributions and comments on the information contained. Please see the "How to Contribute" section for information on contributing your own knowledge.

Table of Contents