Skip to content

Instantly share code, notes, and snippets.

@rctay
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):
try:
if not cursor:
from django.db import connection
cursor = connection.cursor()
if not cursor:
raise Exception
@rctay
rctay / SimpleHTTPServerWithUpload.py
Created Dec 19, 2015 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
View SimpleHTTPServerWithUpload.py
#!/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
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.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
@rctay
rctay / 0.sh
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
View 0.sh
# 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
rctay / sitecustomize.py
Created Jul 24, 2012
[python] start debugger on exception
View sitecustomize.py
#
# original: http://code.activestate.com/recipes/65287/
#
# place in lib/python2.x/sitecustomize.py
import bdb
import sys
def info(type, value, tb):
if hasattr(sys, 'ps1') \
View prune-worker.sh
fly -t ci workers --json | jq '.[] | select(.state=="stalled").name'\
| xargs fly -t ci prune-worker -w
@rctay
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
(click)="onSaveChangesClicked()"
id="details__save-changes"
color="primary">save changes
</button>
</form>
@rctay
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
rctay / docker-compose.yml
Last active Dec 5, 2018
Persist artifacts for concourse builds with minio
View docker-compose.yml
services:
# ...
minio:
image: minio/minio
ports: ["9000:9000"]
command: minio server /data
environment:
- MINIO_ACCESS_KEY=minio
- MINIO_SECRET_KEY=miniosecret
@rctay
rctay / playlist_shuffle.py
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
View playlist_shuffle.py
import requests
import soundcloud
import random
import socket
import subprocess
SOUNDCLOUD_API_KEY = '00000000000000000000000000000000'
PLAYLIST_URL = 'https://soundcloud.com/nervomusic/sets/nervomusic-com'