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:3a4b2f2c7ac6e1b5267c2f1f59ac6c6b
Last active May 3, 2024 10:41
webRTC stun / turn server list
to check if the server works - https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice
stun:
stun.l.google.com:19302,
stun1.l.google.com:19302,
stun2.l.google.com:19302,
stun3.l.google.com:19302,
stun4.l.google.com:19302,
stun.ekiga.net,
stun.ideasip.com,
@sagivo
sagivo / bulk-upsert-from-temporary-table.sql
Created April 18, 2016 19:05 — forked from seanbehan/bulk-upsert-from-temporary-table.sql
Perform an "upsert" from CSV file using Postgres copy command #sql #psql
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 stocks.date = temp.date 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
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 / Foo.sol
Last active January 18, 2018 21:48
Import Obj
pragma solidity ^0.4.0;
// import the contract
import "github.com/sagivo/solidity-utils/contracts/lib/Dictionary.sol";
// 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) {
@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 / foo.js
Created June 2, 2016 19:05
benchmark of vs in
'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
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;
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
@sagivo
sagivo / hello.js
Last active September 30, 2015 16:54
var addon = require('./build/Release/addon');
console.log(addon.hello('Sam')); // will print "Hello Sam"
@sagivo
sagivo / hello.js
Last active September 30, 2015 16:53
var addon = require('./build/Release/addon');
console.log(addon.hello()); // will print 'world'