Skip to content

Instantly share code, notes, and snippets.

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

Baishampayan Ghose ghoseb

🏋️‍♂️
View GitHub Profile
@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 / church_numerals.clj
Created June 12, 2009 19:01 — forked from jimweirich/church_numerals.clj
Church Numerals in Clojure
; Church Numerals in Clojure
;
; Church numerals use anonymous functions to represent numbers.
;
; ((zero f) x) -- returns x
; ((one f) x) -- return (f x)
; ((two f) x) -- return (f (f x))
; ...
(def zero (fn [f] (fn [x] x)))
;;; ghoseb.el -- My customisations in addition to ESK
;;; Author: Baishampayan Ghose <b.ghose@gmail.com>
;;; Time-stamp: "2009-08-01 01:44:30 ghoseb"
(require 'cl)
;;; ----------------------
;;; General customisations
;;; ----------------------
(set-scroll-bar-mode 'nil)
@ghoseb
ghoseb / redis_memo.clj
Created January 1, 2010 11:31 — forked from purcell/redis_memo.clj
Clojure Memoize to Redis
(ns redis-memo
(:require redis)
(:import (java.net URLEncoder)))
;; --------------------------------------------------------------------------------
;; Default connection params
;; --------------------------------------------------------------------------------
(def memo-server {:host "localhost" :port 6379 :db 14})
@ghoseb
ghoseb / log4j.properties
Created January 12, 2010 06:02
Log4J Properties
# log4j.properties
log4j.rootLogger = DEBUG, standard
log4j.appender.standard = org.apache.log4j.RollingFileAppender
log4j.appender.standard.File = logs/project.log
log4j.appender.standard.MaxFileSize=1MB
log4j.appender.standard.MaxBackupIndex=1
log4j.appender.standard.layout = org.apache.log4j.PatternLayout
(defn tests []
[{:name 'suiteA
:total 3
:passed (promise)
:failed (promise)
:success (promise)
:tests [{:name 'testA :success (promise)}
{:name 'testB :success (promise)}
{:name 'testC :success (promise)}]}
{:name 'suiteB
(defn tests []
[{:name 'suiteA
:total 3
:tests [{:name 'testA}
{:name 'testB}
{:name 'testC}]}
{:name 'suiteB
:total 3
:tests [{:name 'testD}
{:name 'testE}
@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 / accounts.clj
Created May 4, 2010 05:52
Simple bank account code
;;; accounts.clj -- Accounts -*- Clojure -*-
;;; Time-stamp: "2010-05-04 11:17:53 ghoseb"
;;; Author: Baishampayan Ghose <bg@infinitelybeta.com>
(ns accounts)
(def *min-bal* 500)
(defstruct account
:name
@ghoseb
ghoseb / with-retries.clj
Created March 18, 2011 14:18
Macro to retry executing some code in case of an exception
(ns test)
(defn try-times
"Try executing a thunk `retries` times."
[retries thunk]
(if-let [res (try
[(thunk)]
(catch Exception e ; can be any exception
(when (zero? retries)
(throw e))))]