Skip to content

Instantly share code, notes, and snippets.

// Solving Knapsack problem using Branch and Bound - Tu Hoang - rebyn@me.com
// The sole question of this problem is: If you have a backpack of capacity C (weight) and you have a list of items which weigh differently (w1, w2, etc) and have different values (p1, p2, etc), which is the best combination of items to meet these requirements:
// 1. the total weight of items doesn't exceed C,
// 2. the total profit is the most possible maximal.
// Simply speaking, if you are a thief and you are stealing stuff from a store, which items should you choose to carry with you in order that you gain the most?
#include <iostream>
#include <iomanip>
#include <fstream>
#define CAPACITY 16
@rebyn
rebyn / vm-setup.sh
Last active August 29, 2015 14:15 — forked from nf/vm-setup.sh
#!/bin/bash -e
echo '
PATH=$HOME/go/bin:$PATH
export GOPATH=$HOME
export CDPATH=.:$HOME/src/golang.org/x:$HOME/go/src:$HOME/src/github.com:$HOME/src/github.com/nf:$HOME/src/github.com/adg
export EDITOR=vim
' >> ~/.profile
sudo apt-get update
# Before
def self.send_request_to_path(request)
request.execute(target_base_url)
rescue Intercom::ServiceUnavailableError => e
if endpoints.length > 1
retry_on_alternative_endpoint(request)
else
raise e
end
end
@rebyn
rebyn / database.yml.erb
Last active August 29, 2015 14:27 — forked from franckverrot/database.yml.erb
Heroku database.yml
<%
require 'cgi'
require 'uri'
begin
uri = URI.parse(ENV["DATABASE_URL"])
rescue URI::InvalidURIError
raise "Invalid DATABASE_URL"
end
@rebyn
rebyn / 1_singlehost.go
Last active September 17, 2015 07:14 — forked from justinas/1_singlehost.go
Go middleware samples for my blog post. http://justinas.org/writing-http-middleware-in-go/
package main
import (
"net/http"
)
type SingleHost struct {
handler http.Handler
allowedHost string
}
@rebyn
rebyn / latency.txt
Created September 24, 2015 08:06 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@rebyn
rebyn / README.md
Created October 10, 2015 15:26 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@rebyn
rebyn / Uncached DNS, new connection
Created October 12, 2015 15:05 — forked from adamkaplan/Uncached DNS, new connection
Use Curl to identify bottlenecks in your service layers.
# SSL request to hostname that is not in DNS
> curl -o /dev/null -w @curlformat https://beta.finance.yahoo.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 255k 0 255k 0 0 233k 0 --:--:-- 0:00:01 --:--:-- 233k
Size: 261255
DNS: 0.522
Connect: 0.536
@rebyn
rebyn / bkadb-data-gen.sh
Created December 5, 2015 21:25 — forked from cmerrick/bkadb-data-gen.sh
Better Know a Database - Redshift Load Data Formats
#!/bin/sh
# OS: Ubuntu 14.01
# Generate data - produces about 200GB on disk, takes a while
DATADIR=tpch-dbgen
SCALE=1000
git clone https://github.com/electrum/tpch-dbgen.git
cd $DATADIR && make && ./dbgen -f -v -C 16 -S 1 -s $SCALE && cd -
@rebyn
rebyn / cmd.sh
Created December 7, 2015 17:13 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/