Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
ryandotsmith / transact-example.js
Last active August 29, 2015 14:11
Chain.com Transaction - Create Bitcoin Transactions in Node.js
var Chain = require('chain-node');
var chain = new Chain(blockChain: 'testnet3');
var req = {
inputs: [{
address: "mxLGQRD9p3MayF7WrUJsyuY4cZdPSH2yA4",
// Private key never leaves this process!
private_key: "cNX5yYSnj6Bd3BEjsfV6ZQyn8hQYYDQB79vjHNkv7NAPazo9GBJT",
}],
outputs: [{
@ryandotsmith
ryandotsmith / transaction-template.json
Last active August 29, 2015 14:11
Chain.com Transaction Template -
{
"inputs": [{
"address": "mxLGQRD9p3MayF7WrUJsyuY4cZdPSH2yA4",
"signatures_required": 1,
"signatures": [{
"address": "mxLGQRD9p3MayF7WrUJsyuY4cZdPSH2yA4",
"public_key": "<insert public key>",
"hash_to_sign": "ac366bdd3eb0ecd64d3d08a7d519d7fe5ceb263a499b135e3158fea04c87a89c",
"signature": "<insert signature>"
}]
+------------------+ +-------------------+
| SDK/Your Process | | Chain API |
+------------------+ +-------------------+
build transaction
+------------------------------------->
transaction template
<-------------------------------------+
@ryandotsmith
ryandotsmith / block-chain-u.js
Last active August 29, 2015 14:13
Block Chain U Code Examples Week 1 Lecture 1
var bitcoin = require('bitcoinjs-lib');
var Chain = require('chain-node');
var chain = new Chain({
blockChain: "testnet3"
});
/*
* key = bitcion.ECKey.makeRandom()
* key.toWIF()
@ryandotsmith
ryandotsmith / ok-http.rb
Created March 17, 2015 03:26
OK, net/http!
require 'json'
require 'net/http'
require 'thread'
require 'openssl'
require 'uri'
module Okhttp
class Conn
def initialize(url)
@ryandotsmith
ryandotsmith / x.html
Created March 17, 2015 21:11
Sending a transaction in the browser
<!doctype html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<p>Balance: <span id="balance"></span></p>
</body>
@ryandotsmith
ryandotsmith / payload.json
Created March 18, 2015 21:15
Chain Notifications Webhook Payload
{
"id": "94d50194-05c8-48bb-94d1-588edf3d286c",
"sequence": 163201,
"created_at": "2015-03-18T18:18:18.446537Z",
"delivery_attempt": 1,
"notification_id": "2d2f54c4-73c8-415f-88b7-2b13452f6851",
"type": "webhook",
"block_chain": "bitcoin",
"transaction": {
"hash": "da02037c03337c24439be90ff6cab0e4b9dec03cc4dbe08d8863763a52dcc0ef",
@ryandotsmith
ryandotsmith / limiter.go
Created July 31, 2015 18:30
HTTP token bucket rate limiting
package main
import (
"log"
"net/http"
"sync"
"time"
"github.com/chain-engineering/papi/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/chain-engineering/papi/api"
@ryandotsmith
ryandotsmith / trie.rb
Created April 12, 2010 20:04
ruby trie for interview
# Foraker, I wanted to give you a fresh code sample; not something that has been lying in my home dir.
# for a year.
# I was reading about tries the other day and decided to implement something in ruby. I built this code
# this morning and it has not gone through any refactorings.
# I want to showcase my ruby knowledge along with knowledge of data structures & algorithms.
@ryandotsmith
ryandotsmith / newton.rb
Created May 5, 2010 01:23
newton's method for computing sqrt
PRECISION = 0.0001
def newtonian_guess( guess,fx,fdx )
loop do
better_guess = guess - ( fx.call( guess ).to_f / fdx.call( guess ).to_f )
return better_guess if ((better_guess - guess).abs <= PRECISION)
guess = better_guess
end
end