This file contains hidden or 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 'sinatra' | |
require 'sinatra-websocket' | |
require 'thin' | |
$logger = Logger.new(STDERR) | |
$logger.level = Logger::INFO | |
set server: 'thin', bind: '127.0.0.1', port: 7777 | |
set namespaces: {} |
This file contains hidden or 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
<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; } |
This file contains hidden or 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
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", |
This file contains hidden or 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/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 |
This file contains hidden or 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
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] = { |
This file contains hidden or 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
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}" |
This file contains hidden or 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 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 |
This file contains hidden or 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
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 = [] |
This file contains hidden or 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 | |
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 |
This file contains hidden or 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |