Skip to content

Instantly share code, notes, and snippets.

Bahman Movaqar bahmanm

Block or report user

Report or block bahmanm

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
bahmanm /
Last active Jan 30, 2019
Groovy and Spock (with Gradle)
#!/usr/bin/env bash
# Initialises a Gradle project with Groovy and Spock.
# How To Use?
# 1. Save the file, e.g. ``
# 2. Make it executable: `$ chmod +x`
# 3. Initialise the project: `$ ./ YOUR_PROJECT_NAME`
bahmanm /
Created Nov 20, 2015
OCaml `List.group_by`
let group_by (f : 'a -> 'b) (ll : 'a list) : ('b, 'a list) Hashtbl.t =
(fun acc e ->
let grp = f e in
let grp_mems = try Hashtbl.find acc grp with Not_found -> [] in
Hashtbl.replace acc grp (e :: grp_mems);
(Hashtbl.create 100)
bahmanm / shapeofthedate.groovy
Last active Nov 17, 2017
Convert dates to alien looking plots using partial sums -
View shapeofthedate.groovy
// This has evolved into a fully-fledged project called DateDreamer.
// Please check the project's page for releases and more information.
@Grab(group='com.github.yannrichet', module='JMathPlot', version='1.0.1')
@Grab(group='org.apache.commons', module='commons-math3', version='3.6.1')
import static java.lang.Math.*
import org.apache.commons.math3.complex.Complex
View grab-packt.groovy
* @author Bahman Movaqar <Bahman AT>
import static org.jsoup.Jsoup.parse
def cookieManager = new CookieManager(null, CookiePolicy.ACCEPT_ALL)
def doc = parse(
new URL('').text
View grab-packt-racket.rkt
#lang racket
;;; Author: Bahman Movaqar <Bahman AT>
(require net/url)
(require sxml)
(require net/uri-codec)
(require net/http-client)
(require (planet neil/html-parsing))
(require net/cookies)
bahmanm / clojure-tricks.clj
Created Apr 15, 2012
Clojure tricks and useful functions/macros
View clojure-tricks.clj
(defn getfn [fname]
"Gets a function by its fully qualified name."
(let [fsym (symbol fname)
nsym (symbol (namespace fsym))]
(require nsym)
(resolve fsym)))
(defn interpolate [s vals]
"Returns the interpolation of string 's' with a map of key/values."
;Keys in 's' are marked with #{key-name} syntax.
bahmanm / csv-load-and-process.clj
Created Aug 13, 2012
Processing CSV contents
View csv-load-and-process.clj
; Suppose you have a CSV file with the first row being the column names
; and the rest being data. Using the following snippet you can process
; the contents passing each row's contents as keyword arguments to
; another function.
; Example CSV structure:
; +----------------------------------------------------------+
; | customer-code | name | e-mail | address | phone |
; +----------------------------------------------------------+
bahmanm / lazy-list-combinations.scm
Created Jan 4, 2015
Computes the combinations of any number of given lists as a lazy sequence.
View lazy-list-combinations.scm
; Copyright Bahman Movaqar <Bahman AT>
; Source ->
; Tests ->
;; Collects the CAR of each list in the given list of lists!
(define (cars list-of-lists)
(map car list-of-lists))
;; Collects the CDR of each list in the given list of lists!
(define (cdrs list-of-lists)
bahmanm / test-runner.el
Created Dec 10, 2014
Simple Maven + JUnit test runner for Emacs.
View test-runner.el
;;; A quick way to run JUnit tests:
;;; `C-x t u` runs all the test cases in a unit.
;;; `C-x t c` runs a single test case.
;;; Simply add the snippet at the end of `init.el` or `.emacs`.
;;; NOTE: It assumes you are using projectile to manage the project.
;;; By Bahman Movaqar
;; runs all test cases in the current class
bahmanm / simple-constraint-problem.groovy
Last active Aug 29, 2015
Solve the constraint equation: A + B = CD - E = FG
View simple-constraint-problem.groovy
* Solve the equation A + B = CD - E = FG
* WHERE A..G in [0,1,2,3,7,8,9]
* AND CD = 10*C + D
* AND FG = 10*F + G
* AND C not 0 and F not 0
* AND different letters are different digits
[0,1,2,3,7,8,9].permutations().findAll {
You can’t perform that action at this time.