Skip to content

Instantly share code, notes, and snippets.

Avatar
🔧

Abe Flansburg aflansburg

🔧
View GitHub Profile
@aflansburg
aflansburg / structural-pattern-matching.py
Created Jun 18, 2021
Naive Use Case of Structural Pattern Matching (Python 3.10)
View structural-pattern-matching.py
# https://www.python.org/dev/peps/pep-0634/
# PEP 634 proposed (and was accepted) Structural Pattern Matching (switch/case)
# for Python (available in 3.10) - as of this Gist,
# prerelease 3.10.0b2 is available
import inspect
F = [
lambda x,y: x+y,
lambda x: x+1,
@aflansburg
aflansburg / skewness_plot.py
Last active Apr 22, 2021
Plots a series using the Seaborn histogram plot with kde and, mean, mode, and median lines in Jupyter / iPython
View skewness_plot.py
## handy multi-plot function for showing mode, median, and mean lines in a distplot
## (but using histplot since distplot is deprecated)
## Author - Abram Flansburg
## Intended for use in Jupyter / iPython
def skewness_plot(series):
"""
Plots a series using the histogram plot with kde and plots, mean, mode, and median lines.
*** Dependencies ***
Series must be a pandas.Series
Seaborn must be imported as sns
@aflansburg
aflansburg / lambda_cloudwatch_slack.js
Created Apr 20, 2021
Node.js Lambda to decompress and parse Cloudwatch Log Event gzipped data and send to Slack
View lambda_cloudwatch_slack.js
// In this scenario - a Cloudwatch Subscription Filter is hooked up to a Node.js lambda's ARN
// (see AWS docs around Log Group subscription filters)
// Will need a webhook for the appropriate Slack channel
const https = require('https');
const zlib = require('zlib');
const options = {
hostname: 'hooks.slack.com',
path: 'SLACK_WEBHOOK_URL',
@aflansburg
aflansburg / null_value_display.py
Last active Apr 15, 2021
Tabular Null Value Check display Function for Pandas Dataframe
View null_value_display.py
# Not my original function - looking for citation
def missing_check(df):
null_val_sum = df.isnull().sum()
total = df.isnull().sum().sort_values(ascending=False) # total null values
percent = (null_val_sum/df.isnull().count()).sort_values(ascending=False)
missing_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
return missing_data
'''
Example:
missing_data(df_with_nulls)
@aflansburg
aflansburg / plot.rb
Last active Apr 7, 2021
Ruby Modules, require, module_function, and Rails
View plot.rb
# imagine this lives at app/lib/complicated_data
module ComplicatedData
def generate_complicated_plot_data(start_date: 30.days.ago, end_date: Date.today, type: nil)
# implementation
end
# module_function ensures the method cannot be overridden or extended
module_function :generate_complicated_plot_data
end
@aflansburg
aflansburg / haversine.rb
Last active Apr 6, 2021
Haversine - Straight Line Distance Between Two Sets of Geographical Coordinates (Latitude, Longitude)
View haversine.rb
# radius of earth in meters
R = 6371000;
def haversine(coord1:, coord2:)
# first add our own radians function since Ruby Math does not have one
radians = -> (degrees) { degrees * (Math::PI / 180)}
# convert latitude degrees to radians
phi_1 = radians.call(coord1[:latitude]);
phi_2 = radians.call(coord2[:latitude]);
@aflansburg
aflansburg / haversine.js
Created Apr 6, 2021
Haversine - Straight Line Distance Between Two Sets of Geographical Coordinates (Latitude, Longitude)
View haversine.js
// see the Haversine formula description here
// https://community.esri.com/t5/coordinate-reference-systems/distance-on-a-sphere-the-haversine-formula/ba-p/902128
function haversine(coord1, coord2){
// radius of earth in meters
const R = 6371000;
// convert latitude degrees to radians
const phi_1 = Math.radians(coord1.latitude);
const phi_2 = Math.radians(coord2.latitude);
@aflansburg
aflansburg / Password.js
Last active Jul 1, 2020
Very basic JS password strength test
View Password.js
class Password {
constructor(password){
this.password = password;
this.getPassword = () => password
this.STRENGTH_CRITERIA = {
length: 8,
alpha_numeric_count: 8,
spec_char_count: 1,
@aflansburg
aflansburg / cyberpunk_vaporwave.itermcolors
Created Jan 13, 2020
Vaporwave / Cyberpunk 2077 iTerm Color Theme/Scheme
View cyberpunk_vaporwave.itermcolors
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.13725490868091583</real>
@aflansburg
aflansburg / chinaFriendlyCaptcha.js
Last active Sep 15, 2020
Creating a China friendly captcha w/ Jquery & Rails view
View chinaFriendlyCaptcha.js
function getCnNumber(x){
if (x > 10 && x <= 20){
const ch = '零一二三四五六七八九十'.split('').map((c, i) => x === i && c).find(s => s);
return '十' + ch;
}
else
return '零一二三四五六七八九十'.split('').map((c, i) => x === i && c).find(s => s);
}
function solveHuman(ans){