Skip to content

Instantly share code, notes, and snippets.

👨‍💻
coding

Sagiv Ofek sagivo

👨‍💻
coding
Block or report user

Report or block sagivo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:88f0196245282f9eb8f0
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 / Permutations
Last active Aug 29, 2015
permutation in ruby
View Permutations
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'
View sorting array of int
import "sort"
func main() {
arr := []int{2,4,3,1}
sort.Ints(arr)
fmt.Println(arr) // => [1,2,3,4]
}
View gist:2398b4ace8f830ad4d56
$ go test -bench=. -benchtime 10s mergesort_test.go
testing: warning: no tests to run
PASS
BenchmarkMSAsync 1 88944871528 ns/op
ok command-line-arguments 92.272s
@sagivo
sagivo / gist:2b8b81e9cf1b3d48ce51
Last active Aug 29, 2015
mergesort async with limit
View gist:2b8b81e9cf1b3d48ce51
func merge_sort_async(l []int, c chan []int) {
if len(l) < 2 {
c <- l
return
}
if len(l) < 500 { //TUNE THIS NUMER AND DONT CREATE EXTRA WORK UNLESS IT'S BIGGER
c <- merge_sort(l)
return
}
mid := len(l) / 2
@sagivo
sagivo / gist:a7f8604dea189b7c4d3f
Last active Aug 29, 2015
benchmarking results
View gist:a7f8604dea189b7c4d3f
$ 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:deac2d4de0eb186c4527
Last active Aug 29, 2015
mergesort and mergesortasync in go
View gist:deac2d4de0eb186c4527
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)
View hello.cc
#include <node.h>
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
You can’t perform that action at this time.