Skip to content

Instantly share code, notes, and snippets.

View tinybike's full-sized avatar

Jack Peterson tinybike

  • Merica
View GitHub Profile
@tinybike
tinybike / print.se
Created August 8, 2015 06:16
Print to stdout in Serpent
event stdout(data)
# prints an array to stdout
# $a: array
# $n: array length
macro log_array($a, $n):
with $i = 0:
while $i < $n:
log(type=stdout, $a[$i])
$i += 1
@tinybike
tinybike / fetch.se
Created August 8, 2015 06:30
Load an array into memory from contract data
# loads an array from contract data
# $a: array
# $n: array length
macro fetch($a, $n):
with $memarray = array($n):
with $i = 0:
while $i < $n:
$memarray[$i] = $a[$i]
$i += 1
$memarray
data stuff[]
def load_stuff_success():
mystuff = array(2)
mystuff[0] = 4
mystuff[1] = 5
save(self.stuff[0], mystuff, items=2)
stuff = load(self.stuff[0], items=2)
@tinybike
tinybike / hex_to_utf16le.js
Created August 9, 2015 13:37
Convert hex to UTF-16LE
function hex_to_utf16le(hex) {
var output = '';
for (var i = 0, l = hex.length; i < l; i += 4) {
output += '\\u' + hex.slice(i+2, i+4) + hex.slice(i, i+2);
}
return JSON.parse('"' + output + '"');
}
#!/usr/bin/env node
var assert = require("assert");
// note: btc.total and btc.balance in BTC, not satoshis!
function calculateRepPercentage(btc, eth, exchangeRate) {
return (eth.balance*exchangeRate + btc.balance) / (eth.total*exchangeRate + btc.total);
}
var test = function (t) {
compiling /home/jack/src/augur-core/src/consensus/center.se
compiling /home/jack/src/augur-core/src/consensus/resolve.se
compiling /home/jack/src/augur-core/src/consensus/payout.se
compiling /home/jack/src/augur-core/src/consensus/redeem_interpolate.se
compiling /home/jack/src/augur-core/src/consensus/redeem_payout.se
compiling /home/jack/src/augur-core/src/consensus/redeem_score.se
compiling /home/jack/src/augur-core/src/consensus/redeem_adjust.se
compiling /home/jack/src/augur-core/src/consensus/score.se
compiling /home/jack/src/augur-core/src/consensus/redeem_resolve.se
compiling /home/jack/src/augur-core/src/consensus/statistics.se
#!/usr/bin/env python
from __future__ import division
import os
import json
import csv
import datetime as dt
BTC_PRICE = 229.27
DATA_DIR = "data"
{
"_id": "-0x27c260497c598ffcf8d32a78284506cf64ba717cc8893a4a909605a19f6a6976",
"branchId": "0xf69b5",
"events": [{
"id": "-0xd7c83c1f39f9a43eae32d12538117ca5f6234e937c10e7b5f88db1adada2f3b5",
"description": "Will Federal Reserve Hike Rates in September 2015?",
"outcome": "0"
}],
"price": "0.7691190609260657807",
"tradingFee": "0.01999999999999999998",
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np
np.set_printoptions(linewidth=120,
suppress=True,
formatter={"float": "{: 0.6f}".format})
@tinybike
tinybike / geth-ipc.c
Created September 25, 2015 23:34
geth ipc connection
/**
* geth ipc connection
* @author Jack Peterson ([email protected])
*/
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <string.h>