Skip to content

Instantly share code, notes, and snippets.

View richmondwang's full-sized avatar
🎯
Focusing

Richmond richmondwang

🎯
Focusing
View GitHub Profile
@richmondwang
richmondwang / cleanup-local-branches.sh
Last active July 13, 2016 03:51
This will 'delete' (git branch -D) all branches containing a substring (prefix) that are already merged to origin/master
#!/bin/sh
# Created by richmondwang
# Required: bash4, git1.7, sed, awk, grep
#
# This will 'delete' (git branch -dl) all branches
# containing a substring (prefix) that are already merged to origin/master
prefix="feature/richmond/"
# only delete my own branches
@richmondwang
richmondwang / .gitignore
Created March 9, 2016 15:58 — forked from octocat/.gitignore
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@richmondwang
richmondwang / selenium-waiters.java
Last active March 16, 2022 14:20
Selenium. Methods for waiting for load and reload.
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.FieldDecorator;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import xxx.CustomFieldDecorator;
@richmondwang
richmondwang / voluptuous_tags.py
Last active August 16, 2016 14:31
Coerces string into separate string tags
class Tags(object):
"""Converts string to tags, a list of string that was separated by comma
"""
def __call__(self, v):
if not isinstance(v, basestring) or v is None:
raise Exception()
tags = map(lambda x: x.strip(), list(v.split(',')))
tags = filter(lambda x: x != '', tags)
return tags
@richmondwang
richmondwang / voluptuous_month.py
Last active August 16, 2016 14:36
Converts string or int to valid Month.
class Month(object):
"""Validates a string as a Month of a year
Args:
return_type (int): NUMBER = 0, WORD = 1, FULL = 2
msg (str): the message when it fails
"""
NUMBER = 0
WORD = 1
FULL = 2
@richmondwang
richmondwang / timezones
Created August 31, 2016 16:40 — forked from ykessler/timezones
HTML list of time zones (Based on Olson tz database)
<select name="timezone" >
<option disabled selected style='display:none;'>Time Zone...</option>
<optgroup label="US (Common)">
<option value="America/Puerto_Rico">Puerto Rico (Atlantic)</option>
<option value="America/New_York">New York (Eastern)</option>
<option value="America/Chicago">Chicago (Central)</option>
<option value="America/Denver">Denver (Mountain)</option>
<option value="America/Phoenix">Phoenix (MST)</option>
<option value="America/Los_Angeles">Los Angeles (Pacific)</option>
@richmondwang
richmondwang / Concat - Voluptuous.py
Last active February 21, 2017 09:00
Concat Key Marker
# -*- coding: utf-8 -*-
from voluptuous import Optional
from operator import is_not
from functools import partial
class Concat(object):
"""
Creates a concatenated Optional Marker for voluptuous
@richmondwang
richmondwang / StartsWith - Voluptuous.py
Created February 21, 2017 08:57
A way to validate keys that start with a given prefix.
# -*- coding: utf-8 -*-
from voluptuous import Marker, Schema
class StartsWith(Marker):
"""
A way to validate keys that start with a given prefix.
Example:
>>> from voluptuous.util import DefaultTo
@richmondwang
richmondwang / python_jose_decode_cognito.py
Last active May 30, 2020 03:08
Gist to decode AWS cognito using the python Jose package
# -*- coding: utf-8 -*-
# pip install python-jose
from jose import jwt
token = "<token here>"
key = {
"alg": "RS256",
"e": "AQAB",
"kid": "+Sr66GHFIwrVWzl9N02mrm96OCoYbNktaekEhXs9+eM=", # <-- this should match the `kid` in the token's headers
@richmondwang
richmondwang / suredict.py
Created March 31, 2017 07:13
This subclass is used for dicts with guaranteed values of children but can still be used like a normal dict.
class SureDict(dict):
"""
This subclass is used for dicts with guaranteed values of children but
can still be used like a normal dict.
.. note::
Note that only the top level will be of class SureDict, those children
whose values are of dict will remain dict.