Skip to content

Instantly share code, notes, and snippets.

View sirupsen's full-sized avatar
🐡

Simon Eskildsen sirupsen

🐡
View GitHub Profile
@sirupsen
sirupsen / hosts.focus
Created March 13, 2013 10:43
My /etc/hosts and the accompanying crontab.
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
@sirupsen
sirupsen / gist:4178574
Last active October 13, 2015 09:58
Implementation of a faster linear search, by sparing a single comparison.
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int sought = 4e8;
vector<int> vec;
for(size_t i = 0; i < sought + 20; i++)
@sirupsen
sirupsen / fast.cpp
Created October 18, 2012 19:24
Code for my competitive programming talk in C++ and Javascript. It solves the "Mega Inversion" problem from NCPC 2011: http://ncpc.idi.ntnu.no/ncpc2011/ncpc2011problems.pdf
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
ll n;
vector<int> numbers;
struct Tree {
@sirupsen
sirupsen / gist:3736027
Last active October 10, 2015 18:58
Implementation of a logarithmic time segment tree tree to update an interval, instead of a single key.
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
struct Tree {
vector<ll> tree;
ll n;
@sirupsen
sirupsen / gist:3317833
Last active October 8, 2015 10:18
Simple program to schedule a reminder on OS X.
#!/bin/bash
at $2 << !!
say $1
osascript -e 'tell app "System Events" to display dialog "Reminder: $1"'
!!
exit 0
@sirupsen
sirupsen / gist:2164021
Last active February 26, 2018 14:28
An extremely simple dynamic programming fibonacci implementation in Ruby using hashes.
# fibonacci
h = Hash.new { |hash,key| hash[key] = hash[key-1] + hash[key-2] }
h[1] = 0
h[2] = 1
@sirupsen
sirupsen / graph.rb
Created January 10, 2012 07:08
Find distance from one Twitter profile to another.
require "net/https"
require "uri"
require 'json'
def request(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@sirupsen
sirupsen / explain.rb
Created December 6, 2011 06:35
.ircrb entry to run explain on a query.
if defined? ActiveRecord
def explain(query)
query = query.to_sql if query.is_a?(ActiveRecord::Relation)
ActiveRecord::Base.connection
.execute("EXPLAIN ANALYZE #{query}")
.to_a
.each { |hash| puts hash["QUERY PLAN"] }
nil
@sirupsen
sirupsen / vim7.3_mac_install.rb
Created July 27, 2011 21:57 — forked from pengwynn/vim7.3_mac_install.rb
Script to install Vim 7.3 with ruby support for Mac OS X Lion
# requires root permissions in /usr/bin/
star = String.new
8.times { star += "*" }
Star = "\n#{star * 3}\n"
def newblock string
puts "\n#{Star}#{string}#{Star}\n"
end
@sirupsen
sirupsen / pvpn
Created April 14, 2011 14:45
Launches shuttle on untrusted networks.
#!/bin/bash
#
# Launches sshuttle if you're on an untrusted network, currently only available on OS X.
# Patches for Linux support welcome!
#
# sshutle: Transparent proxy server that works as a poor # man's VPN.
# Forwards over ssh. Doesn't require admin. Works with Linux and MacOS. Supports DNS tunneling.
# https://github.com/apenwarr/sshuttle
#
# Dependencies