Skip to content

Instantly share code, notes, and snippets.

@rctay
rctay / sitecustomize.py
Created July 24, 2012 09:38
[python] start debugger on exception
#
# 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') \
fly -t ci workers --json | jq '.[] | select(.state=="stalled").name'\
| xargs fly -t ci prune-worker -w
@rctay
rctay / my-component.html
Last active December 19, 2018 08:22
Testing handlers and their bindings
<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 December 19, 2018 01:40
Explicit typing for merging 2 objects/decorating in TypeScript with intersection types
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 December 5, 2018 08:41
Persist artifacts for concourse builds with minio
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 November 14, 2018 19:52
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'
PLAYLIST_URL = 'https://soundcloud.com/nervomusic/sets/nervomusic-com'
@rctay
rctay / foo.md
Last active April 6, 2018 06:04
soliloquy 20180406

Is this refactor warranted?

Before:

    const ROLES = ['boss', 'big boss', 'major boss', 'super boss', 'the boss'];

    describe('with Alpha Team details but', () => {
        describe('without Big Boss', () => {
            const expected_roles = ROLES.filter(role => role !== 'big boss');
def allnumbers(i=1):
while True:
yield i
i += 1
def fastforward(it, till, it_head=None):
n = next(it) if it_head is None else it_head
while n < till:
n = next(it)
return n
function copy(o) {
var p = {};
for (var k in o)
p[k] = o[k];
return p;
}
function Mapper(source) {
this.source = source;
this.result = {};
@rctay
rctay / jk-flipflop.js
Created October 31, 2011 15:03
[js] 2-bit counter with JK flip-flops
function flip(bit) {
return bit ? 0 : 1;
}
// each call simulates clock tick
function jk() {
var q=0;
return function(j, k) {
if (j) {
if (k)