Skip to content

Instantly share code, notes, and snippets.

View nothingmuch's full-sized avatar
🤔

Yuval Kogman nothingmuch

🤔
View GitHub Profile
var ajaxify_forms = function() {
$('form.validate').validate({
debug: true,
submitHandler: function (form) {
var before_submit = $(form).attr('beforeSubmit');
if ( before_submit.length ) {
var f;
eval("f = function () {" + before_submit + "}");
f.apply(form, []);
_update_prompt () {
if [ -z "$_dumb_prompt" ]; then
# if $_dumb_prompt isn't set, do something potentially expensive, e.g.:
git status --porcelain | perl -ne 'exit(1) if /^ /; exit(2) if /^[?]/'
case "$?" in
# handle all the normal cases
...
# but also add a case for exit due to SIGINT
#!/bin/bash
#
# PS1 magic
#
# Mostly copied from YUVAL KOGMAN version, added my own __git_ps1 stuff
# Original: http://gist.github.com/621452
#
# See video demo of this at http://vimeo.com/15789794
#
# To enable save as .bash_prompt in $HOME and add to .bashrc:
#!/bin/bash
_set_prompt () {
local exit=$?
#local black="30";
#local grey="31";
local red="31";
local green="32";
# <file system> <mount point> <type> <options> <dump> <pass>
some_dir /home/nothingmuch/some_dir vboxsf uid=nothingmuch,gid=nothingmuch 0 0
#!/bin/bash
VM="$( basename "$0" )"
if [ -n "$1" ]; then
# explicit control of the VM, e.g. `blah stop`
# useful commands are 'pause', 'resume', 'stop', etc
case "$1" in
status) VBoxManage showvminfo "$VM" | grep -i state ;;
*) VBoxManage controlvm "$VM" ${1/stop/acpipowerbutton} ;; # much easier to type
use MyAwesomeDie qw(die last_trace all_traces previous_error); # tentative
use Try::Tiny;
try {
die [ @some_values ]; # this is not CORE::die
} catch {
# gets data out of SV magic in $_
my $trace = last_trace($_);
# value of $@ just before dying

A bare minimum [Catalyst][1] action can handle about 100 requests per second on my machine last I checked. Another old measurement places [Plack][2] at about 2K on the fastest backends, with absolutely bare minimum request handling.

Most of the real world applications I wrote can handle about 10-20 requests per second on my machine for the quickest dynamic requests.

confess, Throwable::Error, Exception::Class and creating a hash with 100 pairs of short strings are all in the range of 2K-5K iterations per second.

Devel::StackTrace and croak break the 10K iterations per second barrier.

It would take about 100 Devel::StackTrace->new calls per HTTP request to make my real world apps 5% slower, but 10 stack frames deep, it would only take 50 calls to have the same impact.

my $dir = KiokuDB->connect(
$dsn,
# this coerces into a new object
live_objects => {
clear_leaks => 1,
leak_tracker => sub {
my @leaked = @_;
warn "leaked " . scalar(@leaked) . " objects";
my %cache;
sub get { $cache{$_[0]} }
sub set {
my ( $key, $value ) = @_;
if ( keys %cache > $some_limit ) {
... # delete a key from %cache
}