Skip to content

Instantly share code, notes, and snippets.

View danielnegri's full-sized avatar
Coffee first.

Daniel Negri danielnegri

Coffee first.
View GitHub Profile
@danielnegri
danielnegri / gist:7b597c290649164bee791cb1c3611821
Created April 16, 2016 18:12 — forked from alexedwards/gist:dc3145c8e2e6d2fd6cd9
Example of working with Go's database/sql and NULL fields
CREATE TABLE books (
isbn char(14) NOT NULL,
title varchar(255),
author varchar(255),
price decimal(5,2)
);
INSERT INTO books (isbn, title, author, price) VALUES
('978-1503261969', 'Emma', 'Jayne Austen', 9.44),
('978-1514274873', 'Journal of a Soldier', NULL, 5.49),
@danielnegri
danielnegri / PrinceClient.java
Created May 10, 2016 20:28
Converting HTML to PDF with Prince (Java)
package com.ondeck.reportgeneratorapi.services;
import com.princexml.Prince;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
var bitcore = require('bitcore');
var request = require('request');
var utxo = {
'txId' : '0c5d827a24b0822abbff73f1adbfd2be7efaf4e368b4baac7e280865eb13f497',
'outputIndex' : 1,
'script' : 'a91431f2ae5b333c56a4f01df6209382ec8f892e4f3687',
'satoshis' : 1000000
};
@danielnegri
danielnegri / pwdx_for_mac.bash
Created November 15, 2016 20:42 — forked from tobym/pwdx_for_mac.bash
pwdx for mac. Usage: pwx pid
function pwdx {
lsof -a -p $1 -d cwd -n | tail -1 | awk '{print $NF}'
}
@danielnegri
danielnegri / portpwdx.bash
Created November 15, 2016 20:44
Report current working directory of a process by port
# Report current working directory of a process by port
function pwdx {
# lsof -a -p $1 -d cwd -n | tail -1 | awk '{print $NF}'
lsof -a -p $1 -d cwd -n
}
portpwdx () {
pid=$(lsof -i :$1 | tail -1 | perl -pe 's/[^\s]+\s+([^\s]+)\s.*/$1/')
if [[ ! -z $pid ]]
then
@danielnegri
danielnegri / background.js
Created December 2, 2016 15:33 — forked from Rob--W/background.js
Implementation example of writable response bodies for Chromium extensions (API draft).
/**
* Implementation example of writable response bodies.
* Based on the draft of the Streams API (19 March 2014)
* https://dvcs.w3.org/hg/streams-api/raw-file/tip/Overview.htm
* Design document for response body reading/writing:
* https://docs.google.com/document/d/1iE6M-YSmPtMOsec7pR-ILWveQie8JQQXTm15JKEcUT8
*/
/* globals chrome, ByteStream, URL, XMLHttpRequest */
'use strict';
package main
import (
"bufio"
"encoding/csv"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
@danielnegri
danielnegri / golang_job_queue.md
Created April 20, 2017 15:17 — forked from harlow/golang_job_queue.md
Job queues in Golang
@danielnegri
danielnegri / redux-light-example.js
Created July 13, 2017 20:16 — forked from davidbgk/redux-light-example.js
redux in 14 lines of code
const store = createStore((state = { counter: 0 }, action) => {
switch(action.type) {
case "INCREMENT":
return { counter: state.counter + 1 }
case "DECREMENT":
return { counter: state.counter - 1 }
default:
return state
}
})
@danielnegri
danielnegri / howto_nat_traversal.md
Created October 24, 2017 12:59 — forked from mildred/howto_nat_traversal.md
How To TCP NAT Traversal using Node.js and a STUN Server

How To TCP NAT Traversal using Node.js and a STUN Server

With the scarecity of IPv4 addresses, and IPv6 still not available at large, NAT traversal is becoming a necessity. Especially with the generalisation of Carrier-grade NATs that you can find on mobile connections. Even with IPv6 you may suffer NAT66. Imagine your mobile device that gets only a single Ipv6 address, and you want to share it on your computer.

The solution might be in a decentralized protocol for address attribution such