Skip to content

Instantly share code, notes, and snippets.

@jmmills
jmmills / wrapper.pl
Created August 31, 2016 00:11
Wrap any moose class methods with timing data
use 5.20.0;
package Foo;
use Moose;
use Time::HiRes qw[gettimeofday tv_interval ITIMER_VIRTUAL setitimer getitimer];
with 'MooseX::Role::Timer';
use UUID::Tiny ':std';
use namespace::clean;
has 'transaction_id' => (is => 'ro', isa => 'Str', builder => '_build_transaction_id');
@jmmills
jmmills / dec_call_problem.py
Created July 24, 2016 20:56
How to write a decorator that is aware if the wrapped function is called a method or a function
import functools
def dec(f):
@functools.wraps(f)
def w(*args, **kwargs):
# print 'apples' if called a method to an instance
# print 'oranges' if called as a function even if first argument is an object
# if called as a method 'bar' object is args[1]
# if called as a function 'bar' object is args[0]
return f(*args, **kwargs)
get '' => sub {
my $all = param('all')
my $tag = param('tag') || 'es';
my $sql = qw[ select subnet from network where circuit_id=? AND tag_id=5 ];
$sql .= $all? '' : "AND state='active'"
}
from nose.tools import *
from pdb import set_trace
class Frame(object):
def __init__(self, first=0, second=0):
self.first = int(first)
self.second = int(second)
self.value = int(first) + int(second)
self.__next = None
@jmmills
jmmills / gist:dd9498b17ab94871bbcb
Created July 30, 2015 22:34
Update ubuntu docker images apt repos to speed up builds
docker run ubuntu /bin/bash -c 'apt-get update 2>&1 >/dev/null && hostname' | docker commit $(xargs) ubuntu:latest
import rom
import rom.util
import logging
from rq import SimpleWorker, Queue
from redis import Redis
logging.disable(logging.CRITICAL)
class ExampleClass(rom.Model):
use strict;
use warnings;
use 5.16.0;
use Test::More;
use Carp::Always;
our $TEST_STRING = 'this is a test';
package main;
use strict;
use warnings;
use 5.16.0;
use Test::More;
use Carp::Always;
our $TEST_STRING = 'this is a test';
package main;
harlie:tmp.QVgwdIM45p$ cat a.tt
[%- INCLUDE 'b.tt' -%]
a.tt: I am at the bottom
charlie:tmp.QVgwdIM45p$ cat b.tt
b.tt: I am at the top
charlie:tmp.QVgwdIM45p$ tpage a.tt
b.tt: I am at the top
a.tt: I am at the bottom
charlie:tmp.QVgwdIM45p$
# Which statement looks most like the english sentence below?
# Peter, go to the kitchen, get some eggs, make an omelette
# this?
peter.go_to_the_kitchen.get_some_eggs.make_an_omelette()
# or this?
peter.goToTheKitchen.getSomeEggs.makeAnOmelette()