Skip to content

Instantly share code, notes, and snippets.


Sagiv Ofek sagivo

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
sagivo / gist:3a4b2f2c7ac6e1b5267c2f1f59ac6c6b
Last active Jan 21, 2020
webRTC stun / turn server list
View gist:3a4b2f2c7ac6e1b5267c2f1f59ac6c6b
to check if the server works -
View gist:2983f18ffb811b2fec8b
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 / bulk-upsert-from-temporary-table.sql
Created Apr 18, 2016 — forked from seanbehan/bulk-upsert-from-temporary-table.sql
Perform an "upsert" from CSV file using Postgres copy command #sql #psql
View bulk-upsert-from-temporary-table.sql
create temporary table temp (symbol varchar(255), open decimal, high decimal, low decimal, close decimal, volume varchar(255), date date );
create table if not exists stocks (id serial primary key, symbol varchar(255), open decimal, high decimal, low decimal, close decimal, volume varchar(255), date date, created_at timestamp, updated_at timestamp);
copy temp (symbol, date, open, high, low, close, volume) from '/path/to/file.csv' with delimiter ',' csv header;
delete from stocks using temp where = and stocks.symbol = temp.symbol;
insert into stocks (symbol, open, high, low, close, volume, date) select symbol, open, high, low, close, volume, date from temp;
sagivo / Foo.sol
Last active Jan 18, 2018
Import Obj
View Foo.sol
pragma solidity ^0.4.0;
// import the contract
import "";
// have fun
contract Foo {
// declare and use new Dictionary structure
using Dictionary for Dictionary.Data;
Dictionary.Data private dic;
function Foo() public view returns (uint) {
View gist:3e8ff7077585fe97478a
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 / foo.js
Created Jun 2, 2016
benchmark of vs in
View foo.js
'use strict';
const timer = function(name) {
var start = new Date();
return {
stop: function() {
var end = new Date();
var time = end.getTime() - start.getTime();
console.log('Timer:', name, 'finished in', time, 'ms');
sagivo / gist:7473564
Created Nov 14, 2013
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 ( ) will redirect to the node app
View gist:7473564
server {
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;
View encrypt_decrypt.js
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted +='hex');
return crypted;
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
View hello.js
var addon = require('./build/Release/addon');
console.log(addon.hello('Sam')); // will print "Hello Sam"
View hello.js
var addon = require('./build/Release/addon');
console.log(addon.hello()); // will print 'world'
You can’t perform that action at this time.