Skip to content

Instantly share code, notes, and snippets.

View brandomr's full-sized avatar

Brandon Rose brandomr

View GitHub Profile
def treat_number(i):
i = str(i)
i = i.replace('+','')
i = i.replace('-','')
#i = int(i)
if i[0] == '1' and len(i) == 11:
i = i[1:11]
return i
@brandomr
brandomr / email_2_name.py
Last active August 14, 2016 17:13
A email to name matching script
from fuzzywuzzy import process
names = ['Megan Sherman','Jin Zhang','Amr Ahmed','Jeffrey De Fauw','Linus Upson','Jonathan Binghman']
emails = ['[email protected]','[email protected]','[email protected]','[email protected]','[email protected]']
names_cleaned = [i.lower() for i in names]
emails_cleaned = [i.split('@')[0] for i in emails]
for email in emails_cleaned:
print '######'
@brandomr
brandomr / merkle_tree.py
Created December 6, 2016 02:01
implement merkle tree in python
from hashlib import sha256 as sha
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
def m_tree(transactions):
"""Takes an array of transactions and computes a Merkle root"""
sub_t = []
from datetime import datetime
import requests
import json
def find_traffic_time(dt):
epoch = datetime(1970,1,1)
delta_time = (dt - epoch).total_seconds()
epoch_t = str(delta_time).split('.')[0]
# build query
@brandomr
brandomr / gemini.py
Created December 26, 2017 20:34
Class for interacting with Gemini API
class gemini(object):
"""
An object for interacting with the Gemini API. Full Gemini API documentation is
available at https://docs.gemini.com
"""
def __init__(self, gemini_api_key, gemini_api_secret, base_url):
"""
Initializes gemini object.
openapi: 3.0.0
info:
title: "World Modelers Search API"
description: "This API specification is for the World Modelers search."
version: "1.0.0"
paths:
/search:
post:
tags:
date EthiopiaArrivals Itoobiya qaxooti UN abaar shaqada Oromiya gargaar skype
2017-02-28 9834 5.5 4.0 17.75 0.0 4.25 2.25 0.0 19.25
2017-03-31 20515 8.5 3.0 27.0 2.5 5.0 0.0 0.0 21.0
2017-04-30 10797 8.0 0.0 20.0 0.8 5.6 0.0 3.2 13.2
2017-05-31 4876 6.5 1.25 16.75 2.5 3.5 2.5 0.0 14.0
2017-06-30 6184 3.5 1.25 17.0 0.0 2.5 0.0 2.5 14.75
2017-07-31 3311 3.4 0.0 22.8 0.0 1.4 3.0 0.0 18.6
2017-08-31 9288 7.5 0.0 21.25 0.0 3.25 2.25 2.25 21.0
2017-09-30 27144 12.75 1.5 33.25 0.0 2.25 13.0 3.25 25.25
2017-10-31 3229 12.2 0.0 25.2 0.0 6.0 2.4 0.0 15.2
@brandomr
brandomr / es-mapping-update.py
Created November 21, 2022 19:32
es-mapping-update
from elasticsearch import Elasticsearch
import json
es = Elasticsearch('http://localhost:9200')
q = {
"query": {
"match_all": {}
}
}
@brandomr
brandomr / data_profiling.py
Created July 13, 2023 13:54
MIT data profiling to TDS
import io
import pandas
import requests
import json
##########################
# generate dataset metadata
# I assume this will come from the HMI during user upload
##########################
dataset = {
@brandomr
brandomr / gist:cd5aecfbe3376c7f9e76e1fc3aca079f
Created September 6, 2024 20:25
example variable optimization
>>> can you run an optimization to come up with a geothermal power project that will maximize net cash flow at 20 years. Pick only a few key input parameters to optimize
thought: I need to run an optimization to maximize net cash flow for a geothermal power
project over a 20-year period. I will select key input parameters for this optimization.
tool: optimize_power
tool_input: {'input_names': ['no_of_prod_wells', 'flowrate', 'wellhead_temperature',
'geothermal_gradient'], 'input_lower_bounds': [1, 25, 100, 50], 'input_upper_bounds':
[10, 100, 200, 100], 'params_to_minimize': [], 'params_to_maximize': ['cumsum(Cash
Flow)[20]'], 'params_to_target': [], 'target_values': [], 'budget': 100}
observation: {'optimized inputs': {'no_of_prod_wells': 8, 'flowrate': 97.83986294796993,