Skip to content

Instantly share code, notes, and snippets.

View klenwell's full-sized avatar

klenwell klenwell

View GitHub Profile
@klenwell
klenwell / oc_zips.txt
Created October 10, 2023 00:10
CSV list of Orange County CA Zip Codes
# ChatGPT couldn't give this to me so I just spent an hour extracting it from a table on a thirty year-old government website.
#
# In the event I or anyone else needs this in the future...
OC_ZIPS = [92656, 92698, 92801, 92802, 92803, 92804, 92805, 92806, 92807, 92808,
92809, 92812, 92814, 92815, 92816, 92817, 92825, 92850, 92899, 92811, 92821,
92822, 92823, 90620, 90621, 90622, 90624, 92624, 92625, 92626, 92627, 92628,
90630, 92629, 92650, 92609, 92610, 92708, 92728, 92831, 92832, 92833, 92834,
92835, 92836, 92837, 92838, 92840, 92841, 92842, 92843, 92844, 92845, 92846,
92605, 92615, 92646, 92647, 92648, 92649, 92602, 92603, 92604, 92606, 92612,
@klenwell
klenwell / .rubocop.yml
Created September 3, 2018 00:30
Rubocop Config
# Based off: https://gist.github.com/jhass/a5ae80d87f18e53e7b56
AllCops:
Exclude:
- 'bin/**/*'
- 'db/**/*'
- 'config/**/*'
- 'script/**/*'
- 'Guardfile'
- !ruby/regexp /old_and_unused\.rb$/
TargetRubyVersion: 2.5
@klenwell
klenwell / redirect.php
Created January 4, 2017 05:13
WikkaWiki action to redirect a page.
<?php
/**
* Redirect the user to another, existing, wiki page.
*
* Save to actions/redirect/redirect.php
*
* ACL for the page have precedence, therefore the user will not be redirected
* if he is not allowed to see the page. The redirect only occurs if the method is 'show'.
* Append 'redirect=no' as a param to the page URL to be not redirected.
*
@klenwell
klenwell / url_detector.py
Created March 10, 2016 17:30
Python script testing regular expressions to detect URLs in strings.
# -*- coding: utf-8 -*-
"""
URL Detection
I'm looking for a roughly accurate URL counter for spam detection in user-submitted content.
REFERENCES
http://daringfireball.net/2010/07/improved_regex_for_matching_urls
"""
import re
@klenwell
klenwell / migrateDeprecatedLinks.php
Created November 20, 2015 05:30
WikkaWiki script to migrate links from deprecated whitespace-delimiter to new pipe-delimiter format.
@klenwell
klenwell / Flask-App-Engine-Integration-Test.md
Last active February 17, 2017 10:40
A simple integration test for Flask on the Google App Engine platform.

This test example is based on the Google App Engine docs and Flask docs.

To run test:

python tests/test.py ~/google-cloud-sdk/platform/google_appengine/

~/google-cloud-sdk/platform/google_appengine/ is the path to the App Engine SDK.

@klenwell
klenwell / djia.py
Created June 25, 2015 13:44
Simple Scraper for Dow Jones Industrial Average
#
# Simple Scraper for Dow Jones Industrial Average
# With Python 3
#
# INSTALLATION (with pyenv)
# pyenv local 3.4.1
# pip install requests
# pip install beautifulsoup4
# pip install https://github.com/syabro/soupselect/archive/master.zip
#
@klenwell
klenwell / Python-Coin-Flip-Problem.md
Last active August 29, 2015 14:16
Coin Flip Problem

From a comment by aws17576 on MetaFilter:

By the way, I wholeheartedly endorse Persi Diaconis's comment that probability is one area where even experts can easily be fooled. This was demonstrated to me in grad school when my advisor, addressing a roomful of mathematicians, posed this problem:

Person A flips a coin repeatedly, stopping the first time two heads in a row appear. Person B flips a coin repeatedly, stopping the first time a head and then a tail appear in a row. Who will flip the coin more times on average -- A, B, or is there no difference?

He let everyone think for a moment, then took a show of hands. Almost everyone got it wrong.

@klenwell
klenwell / trueskill.py
Last active January 17, 2022 13:18
Trueskill Prediction Simulation
import random
from math import sqrt
from trueskill import TrueSkill, Rating, quality_1vs1, rate_1vs1, BETA
from trueskill.backends import cdf
# From https://github.com/sublee/trueskill/issues/1#issuecomment-10491635
def win_probability(team_rating, opponent_rating):
delta_mu = team_rating.mu - opponent_rating.mu
denom = sqrt(2 * (BETA * BETA) + pow(team_rating.sigma, 2) + pow(opponent_rating.sigma, 2))
win_prob = cdf(delta_mu / denom)
@klenwell
klenwell / websphere.yml
Last active July 4, 2019 18:20
Ansible Playbook to Install WebSphere MQ on Debian Server
#
# This playbook assumes the WebSphere MQ file provided by IBM has already been
# downloaded to a specific directory (target.wd) on the server.
#
# ${target.wd} is a variable representing the working directory on the target
# server the MQ client will be installed.
#
# Note: Although this playbook is designed to be able to be run independently,
# it is in fact part of a longer playbook and therefore may have some other
# unexpected dependencies not reflected here.