Skip to content

Instantly share code, notes, and snippets.

View itsmemattchung's full-sized avatar

Matt Chung itsmemattchung

View GitHub Profile
@itsmemattchung
itsmemattchung / subclass_example.py
Created November 25, 2015 16:13
how to make mistakes in python subclass
class MyOtherClass(object):
def do_something(self):
self.__do_a_new_step()
self.__do_one_more_step()
# Should be subclassing from MyClass
class MyOtherClass(MyClass):
def do_something(self):
self.__do_a_new_step()
self.__do_one_more_step()
@itsmemattchung
itsmemattchung / licenses.py
Created December 3, 2015 08:27
License __dict__ update
# -*- coding: utf-8 -*-
"""
github3.licenses
================
This module contains the classes relating to licenses
See also: https://developer.github.com/v3/licenses/
"""
from __future__ import unicode_literals
[program:uwsgi-{{ project }}-{{ env }}]
command={% if new_relic_enabled %}{{ env_folder }}/bin/newrelic-admin run-program {% endif %}{{ env_folder }}/bin/uwsgi --ini {{ env_folder }}/uwsgi.ini
autostart=true
startsecs=10
stopwaitsecs=35
redirect_stderr=true
stopsignal=QUIT
environment=CELERY_LOADER='django',DJANGO_SETTINGS_CHAIN='www',NEW_RELIC_CONFIG_FILE='/etc/newrelic/new-relic-{{ project }}-{{ env }}-www.ini'
stdout_logfile=/var/log/supervisor/uwsgi-{{ project }}-{{ env }}.log
stderr_logfile=/var/log/supervisor/uwsgi-{{ project }}-{{ env }}-stderr.log
@itsmemattchung
itsmemattchung / wc
Created January 22, 2016 13:51
Home stretch
(github3)Matts-Air:github3.py mattchung$ wc -l tests/*.py | sort
0 tests/__init__.py
17 tests/nbtest.py
17 tests/test_github.py
22 tests/fixtures.py
44 tests/conftest.py
79 tests/test_structs.py
127 tests/utils.py
430 tests/test_repos.py
736 total
@itsmemattchung
itsmemattchung / mocking_tempfile.py
Created January 30, 2016 09:27
Example on mocking a tempfile
import tempfile
import mock
def use_tempfile():
dest_dir = '/tmp'
with tempfile.NamedTemporaryFile(dir=dest_dir, delete=False) as temp_dest:
print "hello world"
return temp_dest
@mock.patch.object(tempfile, 'NamedTemporaryFile')
def call_use_tempfile(temp_file):
# this goes in diplomatico
PROOF_API_BASE_URL = {{ proof_base_url[env] }}
# group_vars/all
proof_base_url:
qa: 'https://proof-qa.whalerockengineering.com'
production: 'https://proof.whalerockengineering.com'
@itsmemattchung
itsmemattchung / Makefile
Last active December 16, 2019 09:30
Makefile example for aws lambda
PROJECT = sample-python-app
FUNCTION = $(PROJECT)
REGION = us-east-1
.phony: clean
clean:
rm -f -r $(FUNCTION)*
rm -f -r site-packages
@itsmemattchung
itsmemattchung / sample-app.py
Created March 11, 2016 16:15
example package for aws lambda that uses netstorage and requests
main.py
netstorage/
netstorage/__init__.py
...
requests/
requests/__init__.py
...
@itsmemattchung
itsmemattchung / Deque.java
Created June 19, 2016 17:56
Deque implementation
package dsandalgs;
public class Deque<E> {
int INIT_QUEUE_SIZE = 8;
int first = 0;
int size = 0;
E[] queue;
public Deque(){
this.queue = (E[]) new Object[this.INIT_QUEUE_SIZE];
@itsmemattchung
itsmemattchung / DMux
Created February 3, 2017 00:21
Dmux implementation
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux.hdl
/**
* Demultiplexor:
* {a, b} = {in, 0} if sel == 0
* {0, in} if sel == 1
*/