Skip to content

Instantly share code, notes, and snippets.

View bcambel's full-sized avatar
🌴
On vacation

Bahadir Cambel bcambel

🌴
On vacation
View GitHub Profile

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

@bcambel
bcambel / csc.clj
Created January 7, 2015 15:35
Cascalog sample
(ns cascalog.conj.tunisia
(:use [cascalog api playground])
(:use [cascalog.contrib.incanter])
(:use [cascalog.util :only [collectify]])
(:use [clojure.contrib.def :only [defnk]])
(:require [cascalog [ops :as c] [vars :as v]])
(:require [clojure.data [json :as json]]))
(bootstrap-emacs)
(ns aud_cas.print_fields
(:use cascalog.api)
(:require [clojure.string :as str])
)
(defn parse_input_record
"Parse the text of the input record into fields in a map"
[input_record]
(let [prefix_string (get (str/split input_record #"\: ") 0)
prefix_pairs (str/split prefix_string #" ")
(ns rbl.feature-extraction.user-agent
(:use [clojure.core.memoize :only [memo]])
(:require [clojure.tools.logging :as log])
(:import [nl.bitwalker.useragentutils UserAgent DeviceType Browser OperatingSystem]))
(defn str->features [string]
(try
(let [user-agent (UserAgent. (or string ""))]
{:browser_group (-> user-agent .getBrowser .getGroup .getName)
:os_group (-> user-agent .getOperatingSystem .getGroup .getName)
@bcambel
bcambel / hadoop.sh
Created January 10, 2015 06:23
Set up Hadoop 2.6 in Ubuntu. Based on http://codesfusion.blogspot.nl/2013/10/setup-hadoop-2x-220-on-ubuntu.html updated to 2.6
sudo apt-get install openjdk-7-jdk
java -version
# java version "1.7.0_25"
# OpenJDK Runtime Environment (IcedTea 2.3.12) (7u25-2.3.12-4ubuntu3)
# OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
cd /usr/lib/jvm
ln -s java-7-openjdk-amd64 jdk
sudo apt-get install openssh-server
set -x LEIN_SNAPSHOTS_IN_RELEASE y
set -x DOCKER_HOST tcp://192.168.59.103:2376
set -x DOCKER_CERT_PATH /Users/bahadir/.boot2docker/certs/boot2docker-vm
set -x DOCKER_TLS_VERIFY 1
set -x LC_ALL en_US.UTF-8
set -x LANG en_US.UTF-8
alias tigs "tig status"
alias gitpatch "git add * -p"
alias gitpm "git push origin master"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer:
" Amir Salihefendic
" http://amix.dk - amix@amix.dk
"
" Version:
" 5.0 - 29/05/12 15:43:36
"
" Blog_post:
" http://amix.dk/blog/post/19691#The-ultimate-Vim-configuration-on-Github
@bcambel
bcambel / fetch.clj
Created January 20, 2015 21:38
Fetch images
(ns fetcher.core
(:use [clojure.java.io :as io])
(:use [net.cgrand.enlive-html]))
(defn fetch-all-images-from-url [src-url dest-folder]
(let [
; get root from src-url: http://google.com/alias1/2/3 ---> http://google.com
root-url (clojure.string/join "/" (take 3 (clojure.string/split src-url #"/")))
; function: if image url starts with "/" ( / character is: \/ in Clojure, ex \a \b etc...) append root url
@bcambel
bcambel / destruct.clj
Created January 21, 2015 12:50
clojure destructuring tutorial
;; all the following destructuring forms can be used in any of the
;; Clojure's `let` derived bindings such as function's parameters,
;; `let`, `loop`, `binding`, `for`, `doseq`, etc.
;; list, vectors and sequences
[zero _ _ three & four-and-more :as numbers] (range)
;; zero = 0, three = 3, four-and-more = (4 5 6 7 ...),
;; numbers = (0 1 2 3 4 5 6 7 ...)
;; maps and sets
@bcambel
bcambel / cluster.py
Created January 26, 2015 13:08
Different Clustering algorithms
"""
=========================================================
Comparing different clustering algorithms on toy datasets
=========================================================
This example aims at showing characteristics of different
clustering algorithms on datasets that are "interesting"
but still in 2D. The last dataset is an example of a 'null'
situation for clustering: the data is homogeneous, and
there is no good clustering.