Skip to content

Instantly share code, notes, and snippets.

@mattkatz
mattkatz / judge_droid.py
Created March 30, 2010 18:41
Judge Droid Lays Down the Law
"""
Lays down the law for your phone, telling it what to do and when
Inspired by docblades' silent_night.py
"""
import android, string, time, math, datetime
from datetime import time, datetime, timedelta
from time import sleep
from threading import Timer
droid = android.Android()
interval_secs = 480
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@schwern
schwern / .gitconfig
Created May 25, 2011 22:02
My git aliases
[alias]
st = status
ci = commit -v
cii = commit -v --interactive
cia = commit -v -a
addi = add --interactive
addchanged = add -u
br = branch
co = checkout
diffwords = diff --word-diff
alias 'peval'="perl -E '
use 5.14.2;
my \$code = shift(@ARGV);
use strict;
use warnings FATAL => q[all];
use Carp::Always;
use Try::Tiny;
use Data::Dump qw( dump );
local \$@;
my \$realcode = qq[
@dgl
dgl / search_cpan.pl
Created October 11, 2011 19:45
acme's search_cpan.pl with threads
#!/usr/bin/perl
use strict;
use threads;
use threads::shared;
use warnings;
use 5.12.0;
use Archive::Peek::Libarchive;
use Parse::CPAN::Packages;
use Path::Class;
use Term::ANSIColor;
@briandfoy
briandfoy / gist:1342877
Created November 6, 2011 13:29
Perl regex escapes by version of their introduction
# compiled by Tom Christiansen
v1.0 \0, \0N,\0NN Match octal character up to octal 077.
v1.0 \N, \NN, \NNN Match Nth capture group (decimal) if not in charclass and that many seen, else (octal) character up to octal 377.
v4.0 \a Match the alert character (ALERT, BEL).
v5.0 \A True at the beginning of a string only, not in charclass.
v1.0 \b Match the backspace char (BACKSPACE, BS) in charclass only.
v1.0 \b True at Unicode word boundary, outside of charclass only.
v1.0 \B True when not at Unicode word boundary, not in charclass.
v4.0 \cX Match ASCII control character Control-X (\cZ, \c[, \c?, etc).
v5.6 \C Match one byte (C char) even in UTF‑8 (dangerous!), not in charclass.
@briandfoy
briandfoy / github2ohloh.pl
Created July 27, 2012 19:43
Add Github projects to Ohloh
#!/usr/bin/perl
use v5.14;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new->max_redirects(5);
my $user = $ENV{GITHUB_USER} // '...';
my @committer_names = ( '...', '...', );
$ENV{OHLOH_USER} //= '...';
@UniIsland
UniIsland / SimpleHTTPServerWithUpload.py
Created August 14, 2012 04:01
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.
"""
@derekwyatt
derekwyatt / execOnChange.sh
Created September 1, 2012 15:32
Executes an arbitrary command when files change.
#!/bin/bash
command="$1"
shift
fileSpec="$@"
sentinel=/tmp/t.$$
touch -t197001010000 $sentinel
while :
do
@rcoh
rcoh / safelythrowable.scala
Last active June 15, 2020 21:32
Safely Catch Throwable
def safely[T](handler: PartialFunction[Throwable, T]): PartialFunction[Throwable, T] = {
case ex: ControlThrowable => throw ex
// case ex: OutOfMemoryError (Assorted other nasty exceptions you don't want to catch)
//If it's an exception they handle, pass it on
case ex: Throwable if handler.isDefinedAt(ex) => handler(ex)
// If they didn't handle it, rethrow. This line isn't necessary, just for clarity
case ex: Throwable => throw ex
}