Skip to content

Instantly share code, notes, and snippets.

@jeffreykegler
jeffreykegler / kv_extend.pl
Created March 11, 2014 02:29
Hypothetical extension to Perl 5's hash initialization
use 5.010;
use strict;
use warnings;
use Data::Dumper;
use Marpa::R2 2.082000;
my $input = <<'END_OF_STRING';
{
name => 'test hash 1',
@jshy
jshy / dozer.pl
Created May 10, 2014 02:56
MongoDB REST Interface in Perl (Mojolicious)
#!/usr/bin/env perl
use Mojolicious::Lite;
use MongoDB;
use MongoDB::OID;
my $mongo_port = shift || 27017;
helper 'mongo' => sub {
my ($self, $name) = @_;
my $host = 'localhost:' . $mongo_port;
@draegtun
draegtun / meta_perl6.pl
Created January 13, 2010 21:25
Perl6 metaprogramming example
#!/usr/bin/env perl6
# see:
# * http://transfixedbutnotdead.com/2010/01/13/anyone_for_metaprogramming/
# * http://transfixedbutnotdead.com/2010/01/14/anyone-for-perl-6-metaprogramming/
# * http://fingernailsinoatmeal.com/post/292301859/metaprogramming-ruby-vs-javascript
# * http://transfixedbutnotdead.com/2010/10/31/perl6-metaprogramming-update/
# below runs on Rakudo Star (2010.10 release).
#! /usr/bin/env perl6
use v6;
my $article_template = slurp("templates/post.html");
my $default_template = slurp("templates/default.html");
my $root_url = "http://strangelyconsistent.org/blog";
my @monthnames = <Jan Feb Mar Apr
May Jun Jul Aug
Sep Oct Nov Dec>;
@GuangchuangYu
GuangchuangYu / violin_plot.R
Created February 8, 2012 03:51
generate violin plot using ggplot2
p <- ggplot(mtcars, aes(factor(cyl),mpg,
fill=factor(cyl),
colour=factor(cyl)))
p1 <- p+geom_violin(alpha=0.3, width=0.5) +
geom_boxplot(width=0.2, outlier.colour=NA)
p2 <- p+geom_violin(alpha=0.3, width=0.5) +
geom_dotplot(binaxis='y', stackdir='center', dotsize=0.5)
@paulmillr
paulmillr / mapreduce.scala
Created March 10, 2012 16:03
Why functional programming matters (aka MapReduce for humans)
import com.cloudera.crunch._
import com.cloudera.scrunch._
class ScrunchWordCount {
def wordCount(inputFile: String, outputFile: String) = {
val pipeline = new Pipeline[ScrunchWordCount]
pipeline.read(from.textFile(inputFile))
.flatMap(_.toLowerCase.split("\\W+"))
.filter(!_.isEmpty())
.count
;; echowuhao's solution to Intro to Vectors
;; https://4clojure.com/problem/6
:a :b :c
@wmorgan
wmorgan / gist:3054620
Created July 5, 2012 16:18
Mustache templating for Clojure
(ns potato.core
(:use [slingshot.slingshot :only [throw+ try+]])
(:use [clojure.string :only [trim split]]))
;; use this provide template values at write time (i.e. not compile time).
;; "name" will be the name of the template variable. "context", when not nil,
;; will be the value previously returned by *template-value* for the enclosing
;; section.
(defn ^:dynamic *template-value* [name context])
with(x, {
f(z)
})
# Which of the following statements is this equivalent to?
#
# a) x$f(x$z)
# b) f(x$z)
# c) x$f(z)
# d) f(z)
@xsawyerx
xsawyerx / datetime.pl
Created July 13, 2012 20:38
Finding Friday the 13th
use strict;
use warnings;
use DateTime;
my $dt = DateTime->new(
day => 13,
year => 2012,
);
my $count = 0;