Skip to content

Instantly share code, notes, and snippets.

View tim-cotten's full-sized avatar

Tim Cotten tim-cotten

View GitHub Profile
@tim-cotten
tim-cotten / deposit-account-1-0-0.sol
Last active June 13, 2019 01:51
Simple Deposit Account (v1.0.0)
pragma solidity >=0.4.22 <0.6.0;
/**
* @title DepositAccount - simple contract that stores ether and allows full or
* partial withdrawals by the account owner.
* @author Tim Cotten <tim@cotten.io>
*/
contract DepositAccount {
address private owner;

Keybase proof

I hereby claim:

  • I am tim-cotten on github.
  • I am cottenio (https://keybase.io/cottenio) on keybase.
  • I have a public key ASDFxRUX5qqoXEy81j1Yl51yVt6ykbWwVKKiQki2QSbZhQo

To claim this, I am signing this object:

@tim-cotten
tim-cotten / gas_calc.sol
Created February 13, 2020 13:34
Ethereum GasEater
uint256 constant MIN_COMMIT = 21000 + 396; // TX cost + initial gas spent reaching assignment of token_amt
@tim-cotten
tim-cotten / gas_eater.sol
Created February 13, 2020 14:03
GasEater example implementation
// Tim Cotten <tim@cotten.io>
// No copyright, no license, no warranty.
pragma solidity >=0.4.22 <0.7.0;
contract GasEater {
uint256 constant MIN_COMMIT = 21000 + 396; // TX cost + initial gas spent reaching assignment of token_amt
uint256 constant MIN_FINAL = 1110; // Required gas for finalizing mint
uint256 constant MIN_WITH_NON_ZERO = 5000 + MIN_FINAL;
uint256 constant MIN_WITH_ZERO = 20000 + MIN_FINAL;
@tim-cotten
tim-cotten / broken-import.py
Last active March 21, 2020 02:21
A broken import script
try:
# download to /tmp
urllib.request.urlretrieve(endpoint, "/tmp/" + filename)
except Exception as e:
exc_info = sys.exc_info()
e = ''.join(traceback.format_exception(*exc_info))
exit({
"statusCode": 500,
"body": json.dumps("Could not download archive file: " + filename) + " " + json.dumps(e)
@tim-cotten
tim-cotten / broken-import2.py
Created March 21, 2020 02:25
It's the zip extraction's fault
try:
# extract archive
with zipfile.ZipFile("/tmp/" + filename, 'r') as archive:
archive.extractall("/tmp/")
except Exception as e:
exit({
"statusCode": 500,
"body": json.dumps("Could not extract archive file: " + filename)
})
@tim-cotten
tim-cotten / broken_zipcode_download.py
Created March 21, 2020 13:58
Zipcode Download (Broken Example) - Fails in AWS Lambda
import sys
import os
import json
import configparser
import datetime
import urllib.request
import zipfile
import traceback
config = configparser.ConfigParser()
@tim-cotten
tim-cotten / subprocess_grep1.py
Created March 26, 2020 14:25
Subprocess Grep Check Output #1
import subprocess
grep_cmd = r'''/bin/grep "msclkid=.* HTTP" /var/log/httpd/ssl_request_log*'''
data = subprocess.check_output(grep_cmd, shell=True)
for line in data:
print(line)
@tim-cotten
tim-cotten / subprocess_grep2.py
Created March 26, 2020 14:32
Subprocess Grep check_output #2
import subprocess
grep_cmd = r'''/bin/grep "msclkid=.* HTTP" /var/log/httpd/ssl_request_log*'''
data = subprocess.check_output(grep_cmd, shell=True, universal_newlines=True).splitlines()
for line in data:
print(line)
@tim-cotten
tim-cotten / semclick_1.py
Created March 26, 2020 21:37
Sketch of a SEMClick Object
import subprocess
class SEMClick:
def __init__(self, log_entry):
print(log_entry)
grep_cmd = r'''/bin/grep -h "msclkid=.* HTTP" /var/log/httpd/ssl_request_log*'''
data = subprocess.check_output(grep_cmd, shell=True, universal_newlines=True).splitlines()
for line in data:
c = SEMClick(line)