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 / vcss.html
Last active April 20, 2016 17:39
Simple Sass like variables in CSS through JavaScript. Obviously not a good idea for production but if you're just hacking a bit locally, why not?
<style class='vcss'>
/*
$container-width: 1280px;
$main-font: 1rem 'Dosis', sans-serif;
$light: #fdfdfd;
$dark: #222;
*/
@import url("http://fonts.googleapis.com/css?family=Dosis");
body { background-color: $light; color: $dark; font: $main-font; }
.container { position: relative; text-align: left; width: $container-width; max-width: 90%; margin: 0 auto; }
@pachacamac
pachacamac / nr26csv.js
Last active April 1, 2016 11:36
Number26 CSV Download Bookmarklet
javascript:(function(){
var delim = ";";
var csv = ["time","subject","amount","currency","original_amount","original_currency","category"].join(delim);
$('.node.activity').each(function(){
csv += "\n" + [
new Date(parseInt(this.dataset.timestamp)).toISOString(),
$('span h4', this)[0].innerText,
parseInt(this.dataset.amount),
"EUR",
@pachacamac
pachacamac / wifi_connector.sh
Last active February 15, 2016 06:33
Workaround for the Ubuntu (NetworkManager?) problem of not being able to connect to a new WiFi network. Or maybe you just prefer to do things conveniently from the CLI.
#/bin/bash
echo "WiFi Networks in range:"
nmcli device wifi list
echo "-----------------------"
echo -n "To which SSID do you want to connect? "
read ssid
echo -n "What is the password for '$ssid'? "
read pass
@pachacamac
pachacamac / bench.js
Created December 30, 2015 02:20
js benchmark wrapper function
var benchmarks = {};
function benchmark(f){
return function(){
var time, result, name = (''+f).split(/\W/,2)[1];
time = performance.now();
result = f.apply(this, arguments);
time = performance.now() - time;
if(!benchmarks[name]){
benchmarks[name] = {
@pachacamac
pachacamac / sphere.rb
Created December 26, 2015 11:54
Photosphere downloader and stitcher
module Enumerable
# inside the block you can use Thread.exit to stop this execution and Thread.exclusive{...} to synchronize stuff
def parallel_map
map{|e| Thread.new{ Thread.current[:result] = yield(e) } }.map{|t| t.join; t[:result]}
end
def parallel_map_in_chunks(chunk_size=8, &block)
chunks = each_slice(chunk_size).each_with_index
chunks.map{|chunk,i|
puts "chunk #{i+1}/#{chunks.size}. chunk_size=#{chunk.size}"
@pachacamac
pachacamac / climage.rb
Created December 7, 2015 00:34
show images on the shell - requires imagemagick
#!/usr/bin/env ruby
def display_image(filename)
tw = `tput cols`.to_i
file = `convert #{filename} -resize #{tw}x ppm:-`.lines
format = file.shift.chomp
raise 'can only read binary format P6' unless format == 'P6'
width, height = file.shift.chomp.split(' ').map(&:to_i)
maxval = file.shift.to_i + 1
bytes = file.join.bytes
@pachacamac
pachacamac / procgen.rb
Last active December 7, 2015 12:34
quick and dirty procedural island generation
class String
def rgb(r,g,b, bg=false) "\033[#{bg ? 48 : 38};5;#{ 16 + 36 * (r/43) + 6 * (g/43) + (b/43) }m#{self}\033[0;00m" end
end
PALETTE = [0x279faf, 0x3ec2d9, 0x86cfd6, 0xc2dcd1, 0xebd8b8, 0xd9be93, 0xc6a16d, 0xa07644, 0x74a044, 0x2e7f21, 0x440044, 0xff0000].map{|c|
[(c & 0xff0000) >> 16, (c & 0x00ff00) >> 8, c & 0x0000ff]}
def show(m, w=nil, h=nil, pal=PALETTE)
(w0,wn),(h0,hn) = m.keys.minmax_by(&:first).map(&:first), m.keys.minmax_by(&:last).map(&:last)
arr = []
@pachacamac
pachacamac / soma.rb
Last active December 2, 2015 21:47
#!/usr/bin/env ruby
require 'json'
def load_json(url) JSON.parse(`wget -q -O- #{url}`) end
class String
#extend: http://misc.flogisoft.com/bash/tip_colors_and_formatting
def black; "\e[30m#{self}\e[0m" end
def red; "\e[31m#{self}\e[0m" end
def green; "\e[32m#{self}\e[0m" end
@pachacamac
pachacamac / 0_reuse_code.js
Created October 4, 2015 23:56
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@pachacamac
pachacamac / visualizer.html
Last active September 11, 2015 17:28
visualize stuff with three js
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>visualize</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r71/three.min.js"></script>
<script src="https://mrdoob.github.io/three.js/examples/js/controls/TrackballControls.js"></script>
</head>
<body>
</body>