Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Jordan Chalupka jordan-chalupka

🚀
View GitHub Profile
View urlencode.sh
#!/bin/sh
alias urlencode='python3 -c "import sys, urllib.parse as ul; print(ul.quote_plus(sys.argv[1]))"'
View this_help.py
help(this)
# Help on module this:
# NAME
# this
# MODULE REFERENCE
# https://docs.python.org/3.7/library/this
# The following documentation is automatically generated from the Python
@jordan-chalupka
jordan-chalupka / zen_of_python.py
Created June 4, 2020 23:04
The Zen of Python
View zen_of_python.py
import this
# The Zen of Python, by Tim Peters
# Beautiful is better than ugly.
# Explicit is better than implicit.
# Simple is better than complex.
# Complex is better than complicated.
# Flat is better than nested.
# Sparse is better than dense.
# Readability counts.
View this_source.py
s = """Gur Mra bs Clguba, ol Gvz Crgref
Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
View view_this_sourcecode.py
import this
import inspect
print(inspect.getsource(this))
@jordan-chalupka
jordan-chalupka / impl_my_sql.go
Created May 31, 2020 17:53
implements my-sql server handler using impl
View impl_my_sql.go
//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
}
@jordan-chalupka
jordan-chalupka / impl_sort.go
Created May 31, 2020 17:41
Using impl to create an implementation of the sort interface
View impl_sort.go
// 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_hash.go
Created May 31, 2020 17:34
Using impl to create an implementation of the hash interface
View impl_hash.go
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 / stock_lambda_function.py
Created October 4, 2019 18:36
lambda function to get stocks from AlphaVantage and push the data to DataDog
View stock_lambda_function.py
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 / get_stock_quote.py
Created October 4, 2019 18:32
Gets a stock quote from AlphaVantage
View get_stock_quote.py
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')
# {