Skip to content

Instantly share code, notes, and snippets.

View jordan-chalupka's full-sized avatar
🚀

Jordan Chalupka jordan-chalupka

🚀
View GitHub Profile
@jordan-chalupka
jordan-chalupka / create_lambda_package.sh
Created July 14, 2019 18:16
create lambda deployment package
pip install numpy -t deployment_package
cp lambda_handler.py deployment_package
(cd deployment_package && zip -r ../package.zip .)
@jordan-chalupka
jordan-chalupka / lambda_function.py
Last active July 14, 2019 18:19
array.ndim Lamdba handler
import numpy as np
def lambda_handler(event, context):
input_array = np.array(event['array'])
num_dimensions = input_array.ndim
return num_dimensions
@jordan-chalupka
jordan-chalupka / delete_branches_merged_into_master.py
Last active July 21, 2019 01:40
Python AWS Lambda function to delete branches which have been merged into master
import subprocess
import os
def run(command):
print(command)
process = subprocess.call(command, shell=True, cwd='/tmp/')
def lambda_handler(event, context):
GITHUB_EMAIL = os.environ['GITHUB_EMAIL']
GITHUB_USERNAME = os.environ['GITHUB_USERNAME']
import tensorflow as tf
def lambda_handler(event, context):
# Simple hello world using TensorFlow
hello = tf.constant('Hello, TensorFlow!')
# Start tf session
sess = tf.Session()
# Run the op
from datadog import datadog_lambda_wrapper, statsd
import time
@datadog_lambda_wrapper
def lambda_handler(event, context):
x = event['x']
y = event['y']
z = event['z']
start_time = time.time()
result = perform_complex_calculation(x, y, z)
@jordan-chalupka
jordan-chalupka / get_stock_quote.py
Created October 4, 2019 18:32
Gets a stock quote from AlphaVantage
import os
from botocore.vendored import requests
def get_stock_quote(symbol):
API_KEY = os.environ['API_KEY']
response = requests.get(f'https://www.alphavantage.co/query?apikey={API_KEY}&function=GLOBAL_QUOTE&symbol={symbol}')
return response.json()['Global Quote']
# get_stock_quote('AAPL')
# {
@jordan-chalupka
jordan-chalupka / stock_lambda_function.py
Created October 4, 2019 18:36
lambda function to get stocks from AlphaVantage and push the data to DataDog
import os
from datadog import datadog_lambda_wrapper, lambda_metric
from botocore.vendored import requests
def get_stock_quote(symbol):
API_KEY = os.environs['API_KEY']
response = requests.get(f'https://www.alphavantage.co/query?apikey={API_KEY}&function=GLOBAL_QUOTE&symbol={symbol}')
return response.json()['Global Quote']
def track_metric(symbol, title, value):
@jordan-chalupka
jordan-chalupka / impl_hash.go
Created May 31, 2020 17:34
Using impl to create an implementation of the hash interface
func (Foo) Write(p []byte) (n int, err error) {
panic("not implemented") // TODO: Implement
}
// Sum appends the current hash to b and returns the resulting slice.
// It does not change the underlying hash state.
func (Foo) Sum(b []byte) []byte {
panic("not implemented") // TODO: Implement
}
@jordan-chalupka
jordan-chalupka / impl_sort.go
Created May 31, 2020 17:41
Using impl to create an implementation of the sort interface
// Len is the number of elements in the collection.
func (Foo) Len() int {
panic("not implemented") // TODO: Implement
}
// Less reports whether the element with
// index i should sort before the element with index j.
func (Foo) Less(i int, j int) bool {
panic("not implemented") // TODO: Implement
}
@jordan-chalupka
jordan-chalupka / impl_my_sql.go
Created May 31, 2020 17:53
implements my-sql server handler using impl
//handle COM_INIT_DB command, you can check whether the dbName is valid, or other.
func (Foo) UseDB(dbName string) error {
panic("not implemented") // TODO: Implement
}
//handle COM_QUERY command, like SELECT, INSERT, UPDATE, etc...
//If Result has a Resultset (SELECT, SHOW, etc...), we will send this as the response, otherwise, we will send Result
func (Foo) HandleQuery(query string) (*server.Result, error) {
panic("not implemented") // TODO: Implement
}