Skip to content

Instantly share code, notes, and snippets.

@rctay
rctay / SimpleHTTPServerWithUpload.py
Created December 19, 2015 15:20 — forked from UniIsland/SimpleHTTPServerWithUpload.py
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
rctay / common.py
Created February 13, 2011 02:59
[python] generator-based implementation of Sieve of Eratosthenes (Euler's mod)
def integers():
i = 1
while True:
yield i
i += 1
def head(iter, n):
return [iter.next() for i in xrange(n)]
@rctay
rctay / .gitmodules
Created December 24, 2010 07:12
tornado: chunked handler (RFC2616)
[submodule "iostream_callback"]
path = iostream_callback
url = git://gist.github.com/753987.git
@rctay
rctay / gae_log_sum.py
Created June 14, 2010 14:34
[gae] deferred stats
"""
Parses GAE single-line logs and computes the sum of the time-related fields:
total time, cpu time and api time.
"""
from operator import add
def parse_file(url_path, file_path):
def parse_line(line):
@rctay
rctay / async-gotchas1.ts
Last active July 14, 2022 04:44
calling a promise in "fire-and-forget" fashion but surprisingly subsequent code wasn't called
// assume just this and you don't have access to its source code
let doAsyncThing: () => Promise<void>;
// another async fn - eg. logging, GA reporting
const doAsyncThingSafe = (): Promise<void> =>
new Promise((resolve, _reject) => {
console.log('🎉did <this> where <this = always needs to be done>🚀');
resolve();
});
export default {
name: 'stretch',
title: 'Stretch',
type: 'document',
fields: [
{
name: 'name',
title: 'Name of stretching exercise',
type: 'string',
},
@rctay
rctay / gist:9829266
Created March 28, 2014 10:01
shuffle/randomize playlist/set tracks in Soundcloud Widget eg. https://w.soundcloud.com/player/?url=http://api.soundcloud.com/users/1539950/favorites
require(["lib/play-manager"], function(a) {
// via http://stackoverflow.com/a/6274381
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [v1.0]
function shuf(o) { for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); }
shuf(a.source.models);
var c = a.getCurrentSound(), p = c ? c.isPaused() : false;
a.playNext(); a.playPrev(); // poor man's refresh of current playing song
if (p) a.pause(c); // preserve first-run state
@rctay
rctay / gist:527113
Created August 16, 2010 15:18
[django] check if db table exists
"""
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 / gist:819924
Created February 10, 2011 04:04
[Java][GAE][Mockito] testing servlet requests/responses
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 September 22, 2019 15:58
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 "$_";