Skip to content

Instantly share code, notes, and snippets.

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

Baishampayan Ghose ghoseb

🏋️‍♂️
View GitHub Profile
@ghoseb
ghoseb / ns-cheatsheet.clj
Last active April 11, 2024 05:28 — forked from alandipert/ns-cheatsheet.clj
Clojure ns syntax cheat-sheet
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix
;; and optionally can refer functions to the current ns.
;;
;; * :import refers Java classes to the current namespace.
;;
;; * :refer-clojure affects availability of built-in (clojure.core)
;; functions.
@ghoseb
ghoseb / factorial.py
Created November 14, 2008 18:58
The evolution of a Python Programmer
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@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)))
@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.
@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 / 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 / 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 / gevent_example.py
Created July 27, 2011 09:27
Gevent spawn / link example
from gevent import monkey; monkey.patch_all()
import gevent
import gevent.greenlet
from functools import partial
from random import random
import urllib
import urllib2
def on_exception(fun, greenlet):
@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."