Skip to content

Instantly share code, notes, and snippets.

View ghoseb's full-sized avatar
🏋️‍♂️

Baishampayan Ghose ghoseb

🏋️‍♂️
View GitHub Profile
@ghoseb
ghoseb / freq.clj
Last active December 12, 2015 08:19
Sample code from Pune Clojure Dojo Meetup session held at 8 feb 2013.
(ns ^{:doc "Word frequencies in a text file."
:author "Baishampayan Ghose <b.ghose@helpshift.com>"}
meetup.freq
(:require [clojure.java.io :as io]
[clojure.string :as s]))
(def stop-word? #{"is" "the" "am" "i" "that" "if"}) ;; fill it up!
;;; all these functions are written in a "point free" style
(def get-lines (comp line-seq io/reader))
@ghoseb
ghoseb / download.sql
Last active December 11, 2015 08:08
Check out what was the first item that you ever downloaded on your Mac OS X
-- Open a SQLite shell by issuing the command below
-- sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV*
select LSQuarantineDataURLString from LSQuarantineEvent order by LSQuarantineTimeStamp asc limit 1;
-- For me, it's GNU Emacs.
-- sqlite> select LSQuarantineDataURLString from LSQuarantineEvent order by LSQuarantineTimeStamp asc limit 1;
-- http://bandwidth.porkrind.org/emacs-builds/Emacs-24.2-universal-10.6.8.dmg
@ghoseb
ghoseb / README.md
Created January 18, 2013 16:00 — forked from candera/README.md

A little Clojure configuration reader

This is a handy bit of code I've written more than once. I thought I'd throw it in here so I can refer back to it later. Basically, it lets you read a config file to produce a Clojure map. The config files themselves can contain one or more forms, each of which can be either a map or a list. Maps are simply merged. Lists correspond to invocations of extension points, which in turn produces a map, which is merged along with everything else.

An Example

Consider the following files:

names.edn

;; (require '[clojure.string :as str] '[clojure.java.shell :as shell] '[taoensso.timbre :as timbre])
(defn with-free-port!
"Attempts to kill any current port-binding process, then repeatedly executes
nullary `bind-port!-fn` (which must return logical true on successful
binding). Returns the function's result when successful, else throws an
exception. *nix only.
This idea courtesy of Feng Shen, Ref. http://goo.gl/kEolu."
[port bind-port!-fn & {:keys [max-attempts sleep-ms]
@ghoseb
ghoseb / gist:4134640
Created November 23, 2012 09:04 — forked from AlexBaranosky/gist:4134522
doseq-indexed
;; Example:
;; (doseq-indexed idx [name names]
;; (println (str idx ". " name)
(defmacro doseq-indexed [index-sym [item-sym coll] & body]
`(let [idx-atom# (atom 0)]
(doseq [~item-sym ~coll]
(let [~index-sym (deref idx-atom#)]
@ghoseb
ghoseb / heady-thrill.md
Created September 2, 2012 16:18
The Heady Thrill of Having Nothing to Do

Is constant stimulation hurting our creativity—and the economy? Scott Adams pays tribute to tedium

By Scott Adams

We’ve won the war on boredom! If you have a smartphone in your pocket, a game console in the living room, a Kindle in your backpack and an iPad in the kitchen, you never need to suffer a minute without stimulation. Yay!

@ghoseb
ghoseb / query.js
Created July 10, 2012 10:49
Sample Query
{
"size": 10,
"from": 0,
"query": {
"filtered": {
"filter": {
"or": [{
"term": {
"publish_id": "1"
}
@ghoseb
ghoseb / cut.clj
Created April 16, 2012 09:32
Cut macro from SRFI-26 in Clojure
;;; http://srfi.schemers.org/srfi-26/srfi-26.html
(defn ^:private cut*
[[a f] form]
(cond
(nil? form) [a f]
(seq? (first form))
(let [[arg-list xform] (cut* [[] '()] (first form))]
(recur [(reduce conj a arg-list) (concat f (list xform))] (next form)))
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)
@ghoseb
ghoseb / scaffold.clj
Created March 16, 2012 12:54
Scaffold by Christophe Grand
(defn scaffold
"Print the ancestor method signatures of a given interface."
[iface]
(doseq [[iface methods] (->> iface
.getMethods
(map #(vector (.getName (.getDeclaringClass %))
(symbol (.getName %))
(count (.getParameterTypes %))))
(group-by first))]
(println (str " " iface))