Skip to content

Instantly share code, notes, and snippets.

View sagivo's full-sized avatar
👨‍💻
coding

Sagiv Ofek sagivo

👨‍💻
coding
View GitHub Profile
@sagivo
sagivo / gist:deac2d4de0eb186c4527
Last active August 29, 2015 14:14
mergesort and mergesortasync in go
func mergeSortAsync(l []int, c chan []int) {
if len(l) < 2 {
c <- l
return
}
mid := len(l) / 2
c1 := make(chan []int, 1)
c2 := make(chan []int, 1)
go mergeSortAsync(l[:mid], c1)
go mergeSortAsync(l[mid:], c2)
@sagivo
sagivo / gist:a7f8604dea189b7c4d3f
Last active August 29, 2015 14:14
benchmarking results
$ go test -bench=. -cpu 4 -benchtime 10s mergesort_test.go
testing: warning: no tests to run
PASS
BenchmarkMSAsync-4 10 1450210929 ns/op
ok command-line-arguments 20.887s
$ go test -bench=. -cpu 4 -benchtime 10s quicksort_test.go
testing: warning: no tests to run
PASS
BenchmarkQS-4 5 2101334470 ns/op
@sagivo
sagivo / gist:2983f18ffb811b2fec8b
Last active April 5, 2019 11:09
mergesort in go
func merge_sort(l []int) []int {
if len(l) < 2 {
return l
}
mid := len(l) / 2
a := merge_sort(l[:mid])
b := merge_sort(l[mid:])
return merge(a, b)
}
@sagivo
sagivo / sorting array of int
Last active August 29, 2015 14:14
sorting in go
import "sort"
func main() {
arr := []int{2,4,3,1}
sort.Ints(arr)
fmt.Println(arr) // => [1,2,3,4]
}
@sagivo
sagivo / Permutations
Last active August 29, 2015 14:09
permutation in ruby
def perm arr, i=0
return p arr if i == arr.size
(i..arr.size-1).each do |j|
arr[i], arr[j] = arr[j], arr[i]
perm arr, i+1
arr[i], arr[j] = arr[j], arr[i]
end
end
perm 'ABC'
var settings = {network: 'live'};
var acceptBitcoin = require('accept-bitcoin');
ac = new acceptBitcoin('YOUR_BITCOIN_ADDRESS', settings);
//generate new key for transaction
key = ac.generateAddress({alertWhenHasBalance: true});
console.log("Hello buyer! please pay to: " + key.address());
key.on('hasBalance', function(amount){
console.log("thanks for paying me " + amount); //do stuff
//transfer the amount recived to your account
key.transferBalanceToMyAccount(function(err, d){
@sagivo
sagivo / gist:3e8ff7077585fe97478a
Created September 10, 2014 05:49
accept-bitcoin sample
var settings = {payToAddress: 'YOUR_BITCOIN_ADDRESS'};
var ac = require('accept-bitcoin')(settings);
//generate new key for transaction
key = ac.generateAddress({alertWhenHasBalance: true});
console.log("Hello buyer! please pay to: " + key.address());
key.on('hasBalance', function(amount){
console.log "thanks for paying me " + amount; //do stuff
//transfer the amount recived to your account
key.transferBalanceToMyAccount(function(err, d){
if (d.status === 'success') console.log("Cool, the bitcoins are in my private account!");
@sagivo
sagivo / gist:7473564
Created November 14, 2013 20:13
node.js api with static homepage for nginx users that visit you site via html will go to static html files. users who use api calls (yoursite.com/v1/ ) will redirect to the node app
server {
listen 0.0.0.0:80;
listen [::]:80 default_server ipv6only=on;
server_name localhost;
access_log /var/log/nginx/app.log;
root /usr/share/nginx/html/app-static;
index index.html;
location /v1 {
proxy_set_header X-Real-IP $remote_addr;