Skip to content

Instantly share code, notes, and snippets.

Baishampayan Ghose ghoseb

Block or report user

Report or block ghoseb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ghoseb / download.sql
Last active Dec 11, 2015
Check out what was the first item that you ever downloaded on your Mac OS X
View download.sql
-- Open a SQLite shell by issuing the command below
-- sqlite3 ~/Library/Preferences/*
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;

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:


View free-port.clj
;; (require '[clojure.string :as str] '[ :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."
[port bind-port!-fn & {:keys [max-attempts sleep-ms]
View gist:4134640
;; 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 /
Created Sep 2, 2012
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 / query.js
Created Jul 10, 2012
Sample Query
View query.js
"size": 10,
"from": 0,
"query": {
"filtered": {
"filter": {
"or": [{
"term": {
"publish_id": "1"
ghoseb / cut.clj
Created Apr 16, 2012
Cut macro from SRFI-26 in Clojure
View cut.clj
(defn ^:private cut*
[[a f] form]
(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)))
View cells.clj
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (
; 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 / scaffold.clj
Created Mar 16, 2012
Scaffold by Christophe Grand
View scaffold.clj
(defn scaffold
"Print the ancestor method signatures of a given interface."
(doseq [[iface methods] (->> iface
(map #(vector (.getName (.getDeclaringClass %))
(symbol (.getName %))
(count (.getParameterTypes %))))
(group-by first))]
(println (str " " iface))
ghoseb /
Created Mar 11, 2012
Some factorial implementations in Python
import operator
# naive recursive solution
def fact1(n):
if n <= 1:
return 1
return n * fact1(n - 1)
fact2 = lambda n: reduce(operator.mul, xrange(1, n + 1))
You can’t perform that action at this time.