Skip to content

Instantly share code, notes, and snippets.

View Koronen's full-sized avatar

Victor Koronen Koronen

View GitHub Profile
@Koronen
Koronen / kthsnittet.rb
Last active February 27, 2016 10:50
KTH-snittet
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'nokogiri', '~> 1.6'
end
require 'csv'
require 'date'
// http://docs.mongodb.org/manual/core/map-reduce/
// $ tail -f /var/log/mongodb/mongodb.log
var map = function(){
print("map");
emit(1, 2);
};
var reduce = function(key, values){
print("reduce");
return Array.sum(values);
{
"id" : "2065201419",
"type" : "CreateEvent",
"actor" : {
"id" : 6863681,
"login" : "sdwalsh",
"gravatar_id" : "e2256e5595d65aba76579e24c1977905",
"url" : "https://api.github.com/users/sdwalsh",
"avatar_url" : "https://avatars.githubusercontent.com/u/6863681?",
"location": "Stockholm, Sweden",
@Koronen
Koronen / Vagrantfile
Created April 12, 2014 18:53
Cross-compile Ruby 2.1.0 for Raspberry Pi (WIP)
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise-server-amd64"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
end
@Koronen
Koronen / resque-stat-hacks.rb
Last active August 29, 2015 13:57
Resque statistics hacks
# Print statistics
failures = Resque::Failure.all(0, -1).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
fbe = Hash.new { |h, k| h[k] = Array.new }
fbc = Hash.new { |h, k| h[k] = Array.new }
failures.each { |ex| fbe[ex['exception']] << ex; fbc[ex['payload']['class']] << ex }; nil
puts fbe.map { |e,jj| [e, jj.size] }.inspect
puts fbc.map { |e,jj| [e, jj.size] }.inspect
# Dump failures as JSON
failures = Resque::Failure.all(0, -1).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
require 'benchmark'
n = 2000000
Benchmark.bm do |x|
arr = 1.upto(1000).to_a
x.report('<<') do
1.upto(n) do |i|
arr << i
end
end
@Koronen
Koronen / .gitignore
Last active December 27, 2015 17:19
SSL Client certificate authentication demo
*.crt
*.key
*.log
*.pem
*.req
.vagrant/
@Koronen
Koronen / heroku_migrate_memcached_service_provider.sh
Created October 23, 2013 12:56
Script to migrate Memcached provider from Couchbase to Memcachier on Heroku.
#!/bin/bash
set -e
if [ $# -lt 1 ]; then
echo "Usage: $0 APP" >&2
exit 1
fi
app="$1"
@Koronen
Koronen / Gemfile
Created October 6, 2013 20:54
A simple TextAid server written in Ruby using Sinatra.
source 'https://rubygems.org'
gem 'rake'
gem 'sinatra'
@Koronen
Koronen / puzzle.out
Last active December 20, 2015 03:19
Programming puzzle: Write a function which given a set of integers determines if there exists a subset such that the sum of its elements is zero.
koronen@paridae$ prolog
GNU Prolog 1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz
| ?- consult('puzzle.pl').
compiling /home/koronen/puzzle.pl for byte code...
/home/koronen/puzzle.pl compiled, 5 lines read - 608 bytes written, 11 ms
yes
| ?- puzzle([]).