Skip to content

Instantly share code, notes, and snippets.

rctay / gist:527113
Created Aug 16, 2010
[django] check if db table exists
View gist:527113
Came up with this for satchmo's downloadable product migration, 0001_split.
def db_table_exists(table, cursor=None):
if not cursor:
from django.db import connection
cursor = connection.cursor()
if not cursor:
raise Exception
rctay /
Created Dec 19, 2015 — forked from UniIsland/
Simple Python Http Server with Upload
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
rctay / gist:819924
Created Feb 10, 2011
[Java][GAE][Mockito] testing servlet requests/responses
View gist:819924
import static org.junit.Assert.*;
import static org.junit.matchers.JUnitMatchers.*; // for non-hamcrest core matchers
import static org.mockito.Mockito.*;
import java.util.HashMap;
import java.util.Map;
rctay /
Last active Sep 22, 2019
tmux: update current shell's environment's ssh agent forwarding info (ie. value of $SSH_AUTH_SOCK) when reconnecting, eg via PuTTY
# next try: `test` before `export`
val=`tmux show-environment | grep '^SSH_AUTH_SOCK='`;\
test -n "$val" && export "$val"
# with the $_ bash-ism:
test -n `tmux show-environment | grep '^SSH_AUTH_SOCK='`\
&& export "$_";
rctay /
Created Jul 24, 2012
[python] start debugger on exception
# original:
# place in lib/python2.x/
import bdb
import sys
def info(type, value, tb):
if hasattr(sys, 'ps1') \
fly -t ci workers --json | jq '.[] | select(.state=="stalled").name'\
| xargs fly -t ci prune-worker -w
rctay / my-component.html
Last active Dec 19, 2018
Testing handlers and their bindings
View my-component.html
<form [formGroup]="teamFormGroup" id="team-details__form">
<input matInput placeholder="Team Name" name="teamName" formControlName="teamName">
<button type="submit" mat-raised-button
color="primary">save changes
rctay / settings-page.po.ts
Created Dec 19, 2018
Explicit typing for merging 2 objects/decorating in TypeScript with intersection types
View settings-page.po.ts
import { $ } from 'protractor';
export interface ChangePasswordDialog {
currentPasswordField: ElementFinder;
incorrectPasswordError: ElementFinder;
submitButton: ElementFinder;
export class SettingsPage extends AppPage {
get changePasswordDialog(): ElementFinder & ChangePasswordDialog {
rctay / docker-compose.yml
Last active Dec 5, 2018
Persist artifacts for concourse builds with minio
View docker-compose.yml
# ...
image: minio/minio
ports: ["9000:9000"]
command: minio server /data
- MINIO_SECRET_KEY=miniosecret
rctay /
Last active Nov 14, 2018
SoundCloud set/playlist shuffle via Python + Requests + mpg123. Ctrl-C for next (press Ctrl-C in quick succession to quit), Ctrl-Z/fg to pause/resume
import requests
import soundcloud
import random
import socket
import subprocess
SOUNDCLOUD_API_KEY = '00000000000000000000000000000000'