Skip to content

Instantly share code, notes, and snippets.

View bkawk's full-sized avatar

Will Hill bkawk

  • Digital Dreams
  • Earth
View GitHub Profile
@bkawk
bkawk / index.js
Last active June 14, 2016 06:06
Search for your name in a bitcoin address
var bitcoin = require('bitcoinjs-lib')
var fs = require("fs")
function randomString(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
@bkawk
bkawk / index.js
Last active June 14, 2016 06:05
Make a bitcoin address and WIF
var bitcoin = require('bitcoinjs-lib')
var fs = require("fs")
function randomString(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
function makePair(params) {
@bkawk
bkawk / index.js
Last active June 14, 2016 07:41
Get unspent transactions and total
var bitcoin = require('bitcoinjs-lib');
var request = require('request');
function getUnspent(address) {
var url ='https://bitcoin.toshi.io/api/v0/addresses/'+address+'/unspent_outputs';
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var body = JSON.parse(body);
var total = 0;
var transactions = [];
@bkawk
bkawk / transaction.js
Last active June 21, 2016 07:50
Bitcoin Transaction with MetaData
// Require the libraries we need to make this magic happen
var bitcoin = require(‘bitcoinjs-lib’);
var request = require(‘request’);
var blockchain = require(‘blockchain.info’);
var blockexplorer = require(‘blockchain.info/blockexplorer’);
// Export this module so you can easily call it from your main application
exports.opReturn = function (message, fromKey, toAddress) {
// Create a new promise that can only resolve or reject
return new Promise(function(resolve, reject) {
@bkawk
bkawk / sortBy.js
Last active July 5, 2016 06:30
Sort objects in array
// SORTS ELEMENTS OF AN ARRAY
// http://jsbin.com/rutumeh/edit?js,console
var sortBy = (function () {
var _toString = Object.prototype.toString,
//the default parser function
_parser = function (x) { return x; },
//gets the item to be sorted
function getImage(url){
return new Promise(function(resolve, reject){
var img = new Image()
img.onload = function(){
resolve(url)
}
img.onerror = function(){
reject(url)
}
img.src = url
@bkawk
bkawk / check-address.js
Created September 19, 2016 12:28
Check BTC Address
$.getScript("../scripts/Sha256.js");
$.getScript("../scripts/BigInt.js");
// ----------------- FUNCTIONS------------------//
function check(address) {
var decoded = base58_decode(address);
if (decoded.length != 25) return false;
var cksum = decoded.substr(decoded.length - 4);
var rest = decoded.substr(0, decoded.length - 4);
@bkawk
bkawk / default
Created April 2, 2017 14:36
nginx reverse proxy with caching and SSL for IPFS
map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ max;
}
server {
listen 443 ssl http2 default_server;
@bkawk
bkawk / confg
Last active April 18, 2017 03:21
Nginx with https and SSL
## Make sure we are up to date and install nginx 
sudo apt-get update
sudo apt-get install nginx
## Once completed lets check the version
sudo nginx -v
## OK let’s configure nginx 
sudo nano /etc/nginx/sites-available/default
@bkawk
bkawk / latlng_promise.js
Created April 22, 2017 03:10
Get users Latitude and Longitude
_getPreciseLocation() {
return new Promise((resolve, reject) => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
if(position){
resolve([position.coords.latitude, position.coords.longitude]);
} else {
reject(Error("We didnt get a location"))
}
});