Skip to content

Instantly share code, notes, and snippets.

user> (iter {for x from 1 to 10}
{reduce x by conj initially [] into odds if (odd? x)}
{reduce x by conj initially [] into evens if (even? x)}
{sum x into sum-odds if (odd? x)}
{sum x into sum-evens if (even? x)}
{returning {:evens evens
:odds odds
:sum-odds sum-odds
:sum-evens sum-evens}})
{:evens [2 4 6 8 10], :odds [1 3 5 7 9], :sum-odds 25, :sum-evens 30}
@nipra
nipra / gist:1174053
Created August 26, 2011 18:24
Python **kwargs like functionality when doing function call
;; Just for fun!
;; If Clojure were like Python, I could have used (asdf **{:a 1 :b 2 :c 3}) when calling asdf
user> (defn asdf
[& {:keys [a b c]}]
[a b c])
#'user/asdf
user> (defmacro call**
[func kw-map]
`(~func ~@(mapcat identity kw-map)))
@nipra
nipra / groupby_ex.clj
Created September 26, 2011 08:38
group-by example
user> (group-by #(cond (and (> % 10)
(< % 20))
:between-10-20
(and (> % 30)
(< % 40))
:between-30-40
(and (> % 90)
(< % 100))
@nipra
nipra / project.clj
Created February 12, 2012 18:42
Scratch project
(defproject scratch "1.0.0-SNAPSHOT"
:description "FIXME: write description"
;; http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.clojure%22
;; http://dev.clojure.org/display/doc/Clojure+Contrib
;; http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go
:dependencies [[org.clojure/clojure "1.3.0"]
[org.mongodb/mongo-java-driver "2.6.3"]
[postgresql/postgresql "9.0-801.jdbc4"]
[mysql/mysql-connector-java "5.1.18"]
[org.apache.lucene/lucene-core "3.4.0"]
@nipra
nipra / project.clj
Created February 13, 2012 04:03
test project
(defproject scratch "1.0.0-SNAPSHOT"
:description "FIXME: write description"
;; http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.clojure%22
;; http://dev.clojure.org/display/doc/Clojure+Contrib
;; http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go
:dependencies [[org.clojure/clojure "1.3.0"]
[org.mongodb/mongo-java-driver "2.6.3"]
[postgresql/postgresql "9.0-801.jdbc4"]
[mysql/mysql-connector-java "5.1.18"]
[org.apache.lucene/lucene-core "3.4.0"]
@nipra
nipra / hello-world.lisp
Created May 9, 2012 10:54
Hello World!
;;; http://www.xach.com/lisp/buildapp/
;;; buildapp --output hello-world --asdf-path ~/asds/ --load hello-world.lisp --entry main
;;; nipra@unlambda:~/Projects/CL$ ./hello-world
(in-package :cl-user)
(defun main (argv)
(declare (ignore argv))
(format t "Hello World!~%"))
scratch> (s/deserialize "some data" :bytes)
; Evaluation aborted.
scratch> (s/deserialize "{\"language\":\"Clojure\",\"library\":\"serialism\",\"authors\":[\"Michael\"]}"
:json)
; Evaluation aborted.
@nipra
nipra / row_count_with_prefix.clj
Created October 31, 2012 17:39
Count rows starting with prefix
(let [f1 (PrefixFilter. (hb/to-bytes "0 "))]
(hb/with-table [table (hb/table "foo_bar_table")]
(hb/with-scanner [scanner (hb/scan table
:filter f1
:caching 1000)]
(loop [n 0]
(if (seq (.next scanner 1000))
(recur (+ n (count (.next scanner 1000))))
n)))))
@nipra
nipra / notes.txt
Created November 13, 2012 10:04
CDH4 Hadoop + HBase Pseudo-distributed Mode installation
# Installing CDH4 on a Single Linux Node in Pseudo-distributed Mode
# https://ccp.cloudera.com/display/CDH4DOC/Installing+CDH4+on+a+Single+Linux+Node+in+Pseudo-distributed+Mode
# Installing CDH4 with MRv1 on a Single Linux Node in Pseudo-distributed mode
# On Ubuntu and other Debian systems
nipra@lambda:Downloads$ wget -cv http://archive.cloudera.com/cdh4/one-click-install/precise/amd64/cdh4-repository_1.0_all.deb
nipra@lambda:Downloads$ sudo dpkg -i cdh4-repository_1.0_all.deb # Adds /etc/apt/sources.list.d/cloudera-cdh4.list ??
nipra@lambda:Downloads$ dpkg -L cdh4-repository # To view the files on Ubuntu systems
# Install CDH4
@nipra
nipra / pom.xml
Created May 14, 2013 08:52 — forked from jnatkins/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Replace the group ID with your group ID -->
<groupId>com.mycompany.hadoopproject</groupId>
<!-- Replace the artifact ID with the name of your project -->
<artifactId>my-hadoop-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>