Skip to content

Instantly share code, notes, and snippets.

View stewartpark's full-sized avatar
🏠
Working from home

Stewart Park stewartpark

🏠
Working from home
View GitHub Profile
@stewartpark
stewartpark / slack_coverage.py
Last active August 7, 2017 12:33
Automated test coverage report. (Jenkins<3Slack)
"""
Slack coverage.py notifier.
Stewart Park <stewartpark92@gmail.com>
It reports test coverage to a Slack channel as a Jenkins bot.
Add this as a post-build/build step once coverage.py generates the html report.
Once everything is properly set up, you can add a badge on your README like below:
[![Coverage.py](http://<jenkins-host>/job/<job-name>/coveragepy/badge.svg)](http://<jenkins-host>/job/<job-name>/coveragepy/)
@stewartpark
stewartpark / setup-gcloud.sh
Last active May 31, 2017 05:15
setup-gcloud.sh
#!/bin/sh
# This script is to set up Google Cloud in CircleCI
# Author: Stewart Park <hello@stewartjpark.com>
#
# Usage:
# (set up GCLOUD_SERVICE_KEY as a base64-encoded json credentials file, GCLOUD_PROJECT_ID as your project ID)
# curl -L https://goo.gl/6pDHc6 | bash
sudo -E env "PATH=$PATH" gcloud --quiet components update
sudo chmod 757 /home/ubuntu/.config/gcloud/logs -R
@stewartpark
stewartpark / circleci-trigger.sh
Last active February 17, 2017 19:18
Simple CircleCI Build Trigger
# This script is to trigger another CircleCI build inside a CircleCI build easily
# Author: Stewart Park <hello@stewartjpark.com>
#
# Usage:
# curl -L https://goo.gl/qU14Wd | PROJECT=username/repo-name API_TOKEN=create-one-on-circleci-config bash
set -e
# Install dependencies
sudo apt-get install jq
@stewartpark
stewartpark / hashitout.py
Created October 11, 2015 21:32
Foo.bar hash it out
#!/usr/bin/env python
def memoize(f):
memo = {}
def helper(*args):
x = str(args)
if x not in memo:
memo[x] = f(*args)
return memo[x]
return helper
@stewartpark
stewartpark / blanace.py
Last active April 20, 2016 21:44
Foo.bar peculiar balance
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
$ time python balance.py
1133135930 ['L', 'R', 'R', 'R', 'L', 'R', 'R', 'L', 'R', 'L', 'L', 'R', 'L', '-', '-', 'R', 'L', '-', '-', 'R']
python balance.py 0.02s user 0.01s system 91% cpu 0.032 total
"""
def inc_one_digit(n):
if n == 'L':
@stewartpark
stewartpark / monty_hall_simul.py
Last active February 25, 2016 08:59
Monty Hall Problem
"""
https://en.wikipedia.org/wiki/Monty_Hall_problem
"""
import random
def do_game(change_selection):
# Initial door
doors = [1, 0, 0]
from pyquery import PyQuery as pq
import requests
open('./video.mp4', 'wb').write(requests.get(pq(url=pq(url='http://dogvideos.tumblr.com/post/93519938318/videohall-how-dogs-react-to-human-barking')('iframe').attr('src'))('video source').attr('src')).content)
@stewartpark
stewartpark / mergesort.py
Created January 29, 2016 23:35
Merge sort
"""
Merge sort
"""
first = lambda l: l[0] if len(l) else None
last = lambda l: l[-1] if len(l) else None
first_half = lambda l: l[:len(l)/2]
last_half = lambda l: l[len(l)/2:]
merge = lambda a, b: (
[first(a)] + merge(a[1:], b) if first(a) < first(b) else [first(b)] + merge(a, b[1:])
@stewartpark
stewartpark / aggregate_gb.py
Last active January 21, 2016 01:53
Aggregate the console output of `ag` and git blame it.
from collections import Counter, defaultdict
from subprocess import check_output
import sys
import re
name_extractor=re.compile(r"\(.+?\)")
e=defaultdict(set)
try:
while True:
@stewartpark
stewartpark / test.java
Created May 25, 2013 09:11
Hello world!
import java.lang.*;
import java.lang.reflect.*;
public class test extends ClassLoader{
byte[] b = {(byte)0xCA,(byte)0xFE,(byte)0xBA,(byte)0xBE,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x32,(byte)0x00,(byte)0x1D,(byte)0x0A,(byte)0x00,(byte)0x06,(byte)0x00,(byte)0x0F,(byte)0x09,(byte)0x00,(byte)0x10,(byte)0x00,(byte)0x11,(byte)0x08,(byte)0x00,(byte)0x12,(byte)0x0A,(byte)0x00,(byte)0x13,(byte)0x00,(byte)0x14,(byte)0x07,(byte)0x00,(byte)0x15,(byte)0x07,(byte)0x00,(byte)0x16,(byte)0x01,(byte)0x00,(byte)0x06,(byte)0x3C,(byte)0x69,(byte)0x6E,(byte)0x69,(byte)0x74,(byte)0x3E,(byte)0x01,(byte)0x00,(byte)0x03,(byte)0x28,(byte)0x29,(byte)0x56,(byte)0x01,(byte)0x00,(byte)0x04,(byte)0x43,(byte)0x6F,(byte)0x64,(byte)0x65,(byte)0x01,(byte)0x00,(byte)0x0F,(byte)0x4C,(byte)0x69,(byte)0x6E,(byte)0x65,(byte)0x4E,(byte)0x75,(byte)0x6D,(byte)0x62,(byte)0x65,(byte)0x72,(byte)0x54,(byte)0x61,(byte)0x62,(byte)0x6C,(byte)0x65,(byte)0x01,(byte)0x00,(byte)0x04,(byte)0x6D,(byte)0x61,(byte)0x69,(byte)0x6E,(byte)0x01,(byte)0x00,(byte)0x