Skip to content

Instantly share code, notes, and snippets.

View mager's full-sized avatar
🏠
Working from home

Mager mager

🏠
Working from home
View GitHub Profile
@mager
mager / sf.json
Created April 12, 2018 17:54
Example SF GeoJSON polygon
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mager
mager / deploy.js
Created February 2, 2018 13:42
Compile & deploy a BigGame contract
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const source = fs.readFileSync(bigGamePath, 'utf8');
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { MNEMONIC, INFURA_HOST } = process.env;
const provider = new HDWalletProvider(MNEMONIC, INFURA_HOST);
const web3 = new Web3(provider);
@mager
mager / lottery.test.js
Last active February 2, 2018 13:36
Testing a lottery contract (snippet)
it('allows an account to enter', async () => {
await lottery.methods.enter().send({
from: accounts[0],
value: web3.utils.toWei('0.015', 'ether'),
});
const players = await lottery.methods.players().call({
from: accounts[0],
});
const balance = await lottery.methods.getBalance().call({
@mager
mager / inbox.sol
Created February 1, 2018 15:09
Inbox contract example
pragma solidity ^0.4.18;
contract Inbox {
string public message;
function Inbox(string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
@mager
mager / ex-stats-tracker-usage.ex
Created June 20, 2017 14:54
ExStatsTracker usage
iex> ExStatsTracker.counter(your_key, 1)
iex> ExStatsTracker.increment(your_key)
iex> ExStatsTracker.gauge(your_key)
iex> ExStatsTracker.timing(your_metric, 1)
iex> ExStatsTracker.histogram(your_metric, 1)
iex> ExStatsTracker.meter(your_metric, 1)
@mager
mager / ex-stats-tracker-config.ex
Created June 20, 2017 14:51
ExStatsTracker Config
config :ex_stats_tracker,
host: “your.statsd.host.com”,
  port: 1234,
  prefix: “your_prefix”
  flush_interval: 10000
  chunk_size: 20
@mager
mager / consul_mut_ex_example.ex
Created March 17, 2017 16:56
Simple consul_mut_ex example using do...while block
iex> ConsulMutEx.lock(“test_key”, max_retries: 0) do
...> :acquired
...> else
...> :failed_to_acquire
...> end
:acquired
@mager
mager / consul_backend.ex
Last active February 14, 2017 03:43
Consul backend for mutex library
defmodule ConsulMutEx.Backends.ConsulBackend do
@moduledoc """
Use Hashicorp's Consul KV store to acquire and release locks.
[Consul documentation](https://www.consul.io/docs/agent/http/kv.html)
"""
alias Consul.Session
@timeout 1000
# Atom settings
@mager
mager / seattle-delivery.py
Last active January 18, 2016 18:28
Seattle delivery
from postmates import PostmatesAPI, DeliveryQuote, Delivery, Location, PostmatesAPIException
key = '[redacted]'
customer_id = '[redacted]'
api = PostmatesAPI(key, customer_id)
pickup = Location('Gather Food LLC', '1440 S. Jackson Street, Seattle, WA', '574-551-2847')
dropoff = Location('Bob', '1040 S. Jackson Street, Seattle, WA', '415-777-9999')
quote = DeliveryQuote(api, pickup.address, dropoff.address)