Skip to content

Instantly share code, notes, and snippets.

@uvtc
uvtc / gist:c1c4cbd6f57c85466e7e
Created July 19, 2014 02:05
Best way to find a particular map in a set of them?
#!/usr/bin/env lein-exec
(def people
#{{:id 1 :name "Gorf"}
{:id 2 :name "Riff"}
{:id 3 :name "Raff"}
;; ... snip lots more
{:id 10000 :name "Grum"}})
;; Quick, find Raff's id!
(ns zow.core)
(def maps [{:a 1 :b 2}
{:a 11 :b 22 :c 5}
{:c 6 :a 7}])
(defn my-merge-maps
[& maps]
(reduce (fn [accum [k v]]
(if (accum k)
(ns zow.core)
(def maps [{:a 1 :b 2}
{:a 11 :b 22 :c 5}
{:c 6 :a 7}])
(defn my-merge-maps
[maps]
(apply merge-with
(fn [curr-val new-val]
@uvtc
uvtc / gist:3062265
Created July 6, 2012 19:24
crunch-it (Clojure)
(ns crunch-it.core
(:gen-class))
(def sample-chars "abcdefghijkl0123456789")
(defn generate-random-strings
"Generates a list (`num` items long) of randomish 10-character strings."
[num]
(for [i (range num)]
(apply str (for [j (range 10)]
@uvtc
uvtc / gist:3495031
Created August 28, 2012 04:46
classroom distribution
;; I want `classrooms` (the accumulator) to end up looking like this:
;; {"A" #{"a" "d" "g" "j"}
;; "B" #{"b" "e" "h"}
;; "C" #{"c" "f" "i"}}
(defn distribute-students
[students teachers]
(let [classrooms (into {} (for [t teachers] [t #{}]))]
(loop [student-pool students ;; We'll pare this down as we go.
classrooms classrooms ;; We'll build this up as we go.
[curr-teacher & more] (cycle teachers)] ;;
(map + [1 2 3 4 5]
[6 7 8 9 10])
;; => ((+ 1 6)
; (+ 2 7)
; (+ 3 8)
; (+ 4 9)
; (+ 5 10))
;;----------------------------------
@uvtc
uvtc / gist:4664608
Last active December 11, 2015 21:48
crunch-it: little benchmark in Perl
#!/usr/bin/env perl
use Modern::Perl;
#use diagnostics;
use List::Util qw/max min sum/;
# TODO: more of the following code needs to be put into functions
if (@ARGV != 1) {
say "Please pass exactly one arg: the number of";
@uvtc
uvtc / gist:5016872
Last active December 14, 2015 02:49
prospective ToC for perl6-tut
basics.md
pod.md
variables.md
numbers-and-math.md
strings-and-unicode.md
lists-and-arrays.md
hashes.md
types.md
context.md
nested-data-structures.md
@uvtc
uvtc / gist:5030169
Last active December 14, 2015 04:39
Template for rakudo/rakudo release announcement
# Announce: Rakudo Perl 6 compiler, Development Release #NN ("NAME")
On behalf of the Rakudo development team, I'm proud to announce the
MONTH 2013 release of Rakudo Perl #NN "NAME". Rakudo is an
implementation of Perl 6 on the Parrot Virtual Machine (see
<http://www.parrot.org>). The tarball for this release is available
from <http://rakudo.org/downloads/rakudo/>.
Please note: This announcement is not for the Rakudo Star
distribution[^1] --- it's announcing a new release of the compiler
@uvtc
uvtc / gist:5030261
Last active December 14, 2015 04:48
Rakudo Star release announcement template
# Announce: Rakudo Star
## A useful, usable, "early adopter" distribution of Perl 6
On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the MONTH 2013 release of "Rakudo Star", a useful and usable
distribution of Perl 6. The tarball for the MONTH 2013 release is
available from <http://rakudo.org/downloads/star/>. A Windows .MSI
version of Rakudo star will usually appear in the downloads area
shortly after the tarball release.