Skip to content

Instantly share code, notes, and snippets.

@dstu
dstu / numpy-shuffle-demo.py
Created March 21, 2013 22:12
Shuffling a list with a numpy.random.RandomState forgets the type of list elements if they're tuples.
import pkg_resources
from collections import namedtuple
from numpy.random import RandomState
print pkg_resources.get_distribution("numpy").version
class Foo(namedtuple("Foo", "x")):
pass
items = [Foo(1), Foo(2), Foo(3)]
@dstu
dstu / gist:4489529
Last active December 10, 2015 20:38 — forked from anonymous/gist:4489522
Is this a bug in Perl?
use strict;
use warnings;
use Data::Dumper;
my $things = { foo => 'bar' };
foreach my $word (qw(foo baz bar quux)) {
my $count = grep { defined } $things->{$word};
print "$count\n";
}
@dstu
dstu / App.java
Last active December 10, 2015 17:29
Demo of bug in handling completion of methods with multiple signatures by semantic-ia-complete-symbol in malabar-mode.
public class App {
public static void main(final String[] args) {
System.out.println("Hey, you guys!!!!");
final Signatures s = new Signatures();
// Auto-complete below should provide several signatures
// for stuff(), but only one is given.
s.
}
}
@dstu
dstu / App.java
Created January 6, 2013 16:29
Demo of bug in handling of enum fields by semantic-ia-complete-symbol in malabar-mode.
public class App {
public static void main(final String[] args) {
System.out.println("Hey, you guys!!!!");
// Auto-complete here should give us a list of values in Option, but it doesn't.
final Option o = Option.
}
}
@dstu
dstu / gist:3180381
Created July 26, 2012 05:12
Perl extended regex demo. Not tested!
my $ssn_regex = qr/^
(\d{3}) # first three digits
[\s\-]* # any whitespace or hyphen
(\d{2}) # next two digits
[\s\-]* # any whitespace or hyphen
(\d{4}) # last four digits
$/msx;
sub normalize_ssn {
my ($raw_ssn) = @_;