Skip to content

Instantly share code, notes, and snippets.

@jtobin
jtobin / error.log
Created Jul 9, 2019
~zod testnet scrollback
View error.log
worker_send_replace 47276 hole
worker_send_replace 47276 crud
%hole event failed:
bail: exit
/:<[18.151 15].[18.169 27]>
/:<[18.152 15].[18.169 27]>
/:<[18.153 15].[18.169 27]>
/:<[18.153 31].[18.153 46]>
/:<[18.224 3].[18.237 13]>
/:<[18.225 3].[18.237 13]>
@jtobin
jtobin / CPS.hs
Created Aug 4, 2018
Some CPS transformations.
View CPS.hs
-- see: http://matt.might.net/articles/cps-conversion
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import Data.Unique
import qualified Text.PrettyPrint.Leijen.Text as PP
@jtobin
jtobin / speedy.hs
Last active Nov 12, 2016
such speed
View speedy.hs
import Data.Vector.Unboxed as U
import System.Random.MWC
main :: IO ()
main = withSystemRandom . asGenIO $ \gen -> do
x <- uniformVector gen 10000000 :: IO (U.Vector Double)
print (U.sum x)
-- jtobin@castor:~/sandbox$ time ./Rand +RTS -s
-- 4999721.338394913
@jtobin
jtobin / optimizing.hs
Created Oct 28, 2016
Tweaking comonadic inference for performance
View optimizing.hs
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
import Control.Comonad
import Control.Comonad.Cofree
@jtobin
jtobin / pp-comonad.hs
Created Oct 27, 2016
Probabilistic programming using comonads.
View pp-comonad.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
import Control.Comonad
import Control.Comonad.Cofree
import Control.Monad
import Control.Monad.ST
@jtobin
jtobin / Prob.hs
Created Oct 18, 2016
A simple embedded probabilistic programming language
View Prob.hs
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Monad
import Control.Monad.Free
import qualified System.Random.MWC.Probability as MWC
data ModelF r =
BernoulliF Double (Bool -> r)
| BetaF Double Double (Double -> r)
@jtobin
jtobin / Metropolis.hs
Created Oct 1, 2016
A Metropolis sampler.
View Metropolis.hs
module Metropolis where
import Control.Monad
import Control.Monad.Primitive
import System.Random.MWC as MWC
import System.Random.MWC.Distributions as MWC
propose :: [Double] -> Gen RealWorld -> IO [Double]
propose location gen = traverse (perturb gen) location where
@jtobin
jtobin / crowdfund.js
Created Mar 3, 2016
Ethereum crowdsale example
View crowdfund.js
var foo = eth.accounts[0];
personal.unlockAccount(foo, 'mypassword');
miner.setEtherbase(foo);
var crowdSrc = "contract token { mapping (address => uint) public coinBalanceOf; event CoinTransfer(address sender, address receiver, uint amount); function token(uint supply) { if (supply == 0) supply = 10000; coinBalanceOf[msg.sender] = supply; } function sendCoin(address receiver, uint amount) returns(bool sufficient) { if (coinBalanceOf[msg.sender] < amount) return false; coinBalanceOf[msg.sender] -= amount; coinBalanceOf[receiver] += amount; CoinTransfer(msg.sender, receiver, amount); return true; } } contract Crowdsale { address public beneficiary; uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price; token public tokenReward; Funder[] public funders; event FundTransfer(address backer, uint amount, bool isContribution); struct Funder { address addr; uint amount; } /* runs on init */ function Crowdsale( address _beneficiary , uint _fundingGoal , uint _duration , uint _pric
@jtobin
jtobin / mine.log
Created Feb 29, 2016
Ethereum mining attempt log
View mine.log
vagrant@debian-jessie:~$ mkdir stackexchange-example-chain
vagrant@debian-jessie:~$ geth --genesis local_genesis.json --datadir stackexchange-example-chain --ne
tworkid 9991 --nodiscover --maxpeers 0 account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {699ec6d49641e59f65ba4bf72c52628059301e64}
vagrant@debian-jessie:~$ geth --genesis local_genesis.json --datadir stackexchange-example-chain --networkid 9991 --nodiscover --maxpeers 0 console
I0215 10:08:11.260323 ethdb/database.go:71] Alloted 16MB cache to stackexchange-example-chain/chaindata
I0215 10:08:11.288895 ethdb/database.go:71] Alloted 16MB cache to stackexchange-example-chain/dapp
@jtobin
jtobin / local_genesis.json
Created Feb 29, 2016
Ethereum genesis block
View local_genesis.json
{
"nonce": "0xcafebabecafebabe",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0",
"gasLimit": "0xfffffff",
"difficulty": "0x400",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {
You can’t perform that action at this time.