Skip to content

Instantly share code, notes, and snippets.

View sirupsen's full-sized avatar
🐡

Simon Eskildsen sirupsen

🐡
View GitHub Profile
@sirupsen
sirupsen / omg.c
Created February 14, 2014 13:48
Virtual memory to physical memory.
$ ps -o rss,command | grep ./omg | grep -v grep
488 ./omg
$ ps -o rss,command | grep ./omg | grep -v grep
10268 ./omg
@sirupsen
sirupsen / gist:7111270
Last active December 26, 2015 06:58
Standard I/O examples in a few languages for Contestrus. You get two numbers from standard input and have to output the sum to standard output.
var fs = require("fs");
input_lines = fs.readFileSync('/dev/stdin').toString().split('\n').map(function(s) {
return s.trim();
});
nums = input_lines[0].split(' ').map(Number)
console.log(nums[0] + nums[1])
@sirupsen
sirupsen / gist:7104058
Last active December 26, 2015 05:58
Vendor all the things with Bundler. This is ~/.bundler/config.
---
BUNDLE_PATH: ./vendor/bundle
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_JOBS: 3
@sirupsen
sirupsen / segment_tree.go
Created September 15, 2013 23:26
Implementation of a general segment tree in Go.
package segment_tree
import "fmt"
const sizeMultiplier int = 3
type Comparator func(int, int) int
type Node struct {
set bool
@sirupsen
sirupsen / gist:6575106
Created September 15, 2013 23:12
RSA implementation in C++ with an accompanying naive cracker.
#include<iostream>
#include<gmpxx.h>
#include<gmp.h>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;
void set_prime(mpz_t rop)
{
@sirupsen
sirupsen / README.md
Created September 15, 2013 16:10
Solution to an algorithmic problem using LCA to compute the distance between two nodes in a tree in logarithmic time.

Solution to the Flea Circus problem. It uses a range minimum query segment tree to compute the lowest common ancestor between two nodes in the tree, thus the distance from one node in a tree to another can be computed in O(log n) time, and the tree can be built in O(log(n) n) time. This allows the entire problem to be solved in O(log(n) n) time.

@sirupsen
sirupsen / hipsterfm.rb
Created September 15, 2013 16:01
How hipster is your taste in music?
require 'lastfm'
LASTFM_API_KEY = ""
LASTFM_SECRET = ""
SIRUPSEN = "f6b7ffe9b0c87fe8a341eb7a474f4574"
def get_token
lastfm = Lastfm.new(LASTFM_API_KEY, LASTFM_SECRET)
token = lastfm.auth.get_token
@sirupsen
sirupsen / redis_queue.rb
Created September 15, 2013 15:59
Wrap Redis queues in an enumerable.
class RedisQueue
include Enumerable
def initialize(queue)
@queue = queue
end
def each(&block)
while element = redis.lpop(@queue)
block.call(*JSON.parse(element))
@sirupsen
sirupsen / segment_tree.c
Last active December 23, 2015 02:39
Memory mapped minimum range segment tree.
/*
* This is a simple example of using memory mapped I/O with a data structure.
* The data structure used is a minimum query segment tree. This data structure
* can answer queries of which value in some interval from i..j is the minimum
* in O(log(n)) time. Updates are also O(log(n)).
*
* The data structure is persisted to the file passed as the first argument to
* the compiled program. Memory mapped I/O is nice because:
*
* 1. You get the speed and convenience of accessing memory.
@sirupsen
sirupsen / gist:6481936
Last active May 4, 2019 05:07
Ruby implementation of a trie to use for a Letterpress/Wordfeud/Scrabble cheater.
require 'benchmark'
class SlowTrie
attr_accessor :word, :nodes
def initialize
@word, @nodes = false, {}
end
def <<(word)