Skip to content

Instantly share code, notes, and snippets.

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

Baishampayan Ghose ghoseb

🏋️‍♂️
View GitHub Profile
@ghoseb
ghoseb / file_cols.clj
Last active April 10, 2022 17:03
Print the source-line length of a bunch of files as a histogram.
(ns file-cols.core
"Print the source-line length histogram of a bunch of files as a histogram.
Inspired by: https://gist.github.com/rsms/36bda3b5c8ab83d951e45ed788a184f4"
(:require [clojure.java.io :as io]))
(def uni-bar
"Unicode bars for histogram."
["" "" "" "" "" "" "" "" ""])
(def quot-rem-8
@ghoseb
ghoseb / vi-lineage.txt
Last active March 11, 2021 21:51
The lineage of Vi
Colossal Typewriter
by John McCarthy and Roland
Silver for the PDP-1 | Photon typesetter
? | editors by Michael
? \ Barnett & Kalon
Expensive Typewriter CREATE/EDIT \ Kelley for TECO
for PDP-1 by Steve Piner for CTSS \ IBM 704 for PDP-1
/ | / | \ \__ \ by Dan Murphy
/ | / | \ \ \ |
* Expensive Typewriter editors EDITS | MEMO/MODIFY | | VEDIT |
@ghoseb
ghoseb / clj_spec_playground.clj
Last active March 30, 2019 22:35
Examples of Clojure's new clojure.spec library
(ns clj-spec-playground
(:require [clojure.string :as str]
[clojure.spec :as s]
[clojure.test.check.generators :as gen]))
;;; examples of clojure.spec being used like a gradual/dependently typed system.
(defn make-user
"Create a map of inputs after splitting name."
([name email]
@ghoseb
ghoseb / uniquify.clj
Created January 15, 2014 07:09
Uniquify buffer names
(ns ^{:doc "Uniquify"
:author "Baishampayan Ghose <b.ghose@helpshift.com>"}
uniquify
(:require [clojure.string :refer [join]]))
(defn explode
"Explode a directory name to its subcomponents."
[^String dir]
(seq (.split dir "/")))
@ghoseb
ghoseb / rover.clj
Last active November 9, 2022 03:19
Mars rover problem solved in Clojure.
(ns mars.rover)
;; A squad of robotic rovers are to be landed by NASA on a plateau on
;; Mars.
;; This plateau, which is curiously rectangular, must be navigated by the
;; rovers so that their on-board cameras can get a complete view of the
;; surrounding terrain to send back to Earth.
;;; 99 bottles of beer in Clojure
(def bottles "
# 99 Bottles of Beer
# Brainfuck version
# by Michal Wojciech Tarnowski
+>+++++++[>>>+++
+++++<<<<+++++
@ghoseb
ghoseb / prime_sieve.clj
Last active April 22, 2016 08:05
A concurrent prime sieve in Clojure using core.async
(ns prime-sieve
(:require [clojure.core.async :as async :refer [chan go <! >!]]))
;;; concurrent prime sieve in Clojure using core.async
;; inspired by a similar implementation in Go
;; http://golang.org/doc/play/sieve.go
(defmacro go-forever
"An infinite loop that runs in a go block."
; STM history stress-test
(defn stress [hmin hmax]
(let [r (ref 0 :min-history hmin :max-history hmax)
slow-tries (atom 0)]
(future
(dosync
(swap! slow-tries inc)
(Thread/sleep 200)
@r)
@ghoseb
ghoseb / props.clj
Last active December 16, 2015 03:49
A simple problem that I solved at the April '13 meetup of Pune Clojure Users' Group. The problem is about parsing a Java properties file into Clojure & back.
(ns props.core
(:require [clojure.string :refer [split]]
[clojure.java.io :refer [reader]])
(:import java.util.Properties))
(defn- split-key
"Split a string key to its subparts.
foo -> [foo]
foo.bar.baz -> [foo bar baz]"
@ghoseb
ghoseb / props.clj
Last active December 12, 2015 08:28
Read a Java Properties file into a map (with potentially nested keys).
(ns ^{:doc "Read Java properties file."
:author "Baishampayan Ghose <b.ghose@gmail.com>"}
in.freegeek.props
(:import java.util.Properties)
(:require [clojure.java.io :refer [resource reader]]
[clojure.string :refer [split]]))
(defn- load-props
"Load a Java properties file. File should be in classpath."
[props-file]