Skip to content

Instantly share code, notes, and snippets.

@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) = @_;
@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 / 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 / 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 / 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:8838521
Last active August 29, 2015 13:56
scalac/sbt crash
$ sbt compile
Loading /usr/share/sbt/bin/sbt-launch-lib.bash
[info] Loading project definition from /home/stu/projects/scala-trees/project
[info] Set current project to PCFG parsing (in build file:/home/stu/projects/scala-trees/)
[info] Updating {file:/home/stu/projects/scala-trees/}scala-trees...
[info] Resolving org.scala-lang#scala-library;2.10.3 ...
[info] Resolving org.scalatest#scalatest_2.10;2.0 ...
[info] Resolving org.scala-lang#scala-reflect;2.10.0 ...
[info] Resolving org.scala-lang#scala-compiler;2.10.3 ...
[info] Resolving org.scala-lang#scala-reflect;2.10.3 ...
@dstu
dstu / Item.java
Last active August 29, 2015 13:57
Trying to get Scala to use a proper switch statement on a Java enum type
public enum Item {
ITEM1, ITEM2, ITEM3,
}
@dstu
dstu / test.scala
Created April 2, 2014 05:24
Failure to find type class implementation with Scala 2.10.4, Macro Paradise 2.0.0-M6
package mymacro.test
import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.Context
trait MyTypeClass[T] {
def something: Int
}
@dstu
dstu / test.scala
Created April 3, 2014 04:56
Can't locate typeclass implementation during macro expansion
package mymacro.test
import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.Context
trait MyTypeClass[T] {
def something(c: Context): c.Tree
}
@dstu
dstu / errordemo.scala
Created April 21, 2014 20:13
Dead code error in Scala macro definintion
package errordemo
import scala.annotation.StaticAnnotation
import scala.reflect.macros.whitebox.Context
class mymacro extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro MacroImpl.macroImpl
}
class MacroImpl(val c: Context) {