This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################################################################################### | |
# Compares the elements at `i` and `j` in `list` and swaps them if necessary. | |
##################################################################################################### | |
: COMPARE-AND-SWAP ( list i j -- ) | |
2DUP ( list i j i j ) | |
5 PICK .< get(Integer)/1 >. ( list i j i e_j ) | |
SWAP 5 PICK .< get(Integer)/1 >. ( list i j e_j e_i ) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using nested try-catch blocks. | |
* | |
* @param str a string representing an integer | |
* @return smallest integer type or null | |
*/ | |
Number atoi_NestedTryCatch(String str) { | |
try { | |
return Integer.valueOf(str); | |
} catch (NumberFormatException ignore1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; to save an object into a json file | |
(with-temp-buffer | |
(json-insert '(:foo "bar")) | |
(write-file "~/tmp/my.json")) | |
;; load a json file as hash table | |
(with-temp-buffer | |
(insert-file-contents "~/tmp/my.json") | |
(json-parse-buffer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
### | |
# Initialises a Gradle project with Groovy and Spock. | |
# | |
# How To Use? | |
# | |
# 1. Save the file, e.g. `gradle-init.sh` | |
# 2. Make it executable: `$ chmod +x gradle-init.sh` | |
# 3. Initialise the project: `$ ./gradle-init.sh YOUR_PROJECT_NAME` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// This has evolved into a fully-fledged project called DateDreamer. | |
// Please check the project's page for releases and more information. | |
// https://github.com/bahmanm/datedreamer | |
// | |
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let group_by (f : 'a -> 'b) (ll : 'a list) : ('b, 'a list) Hashtbl.t = | |
List.fold_left | |
(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); | |
acc) | |
(Hashtbl.create 100) | |
ll;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Bahman Movaqar <Bahman AT BahmanM.com> | |
*/ | |
@Grab('org.jsoup:jsoup:1.8.2') | |
import static org.jsoup.Jsoup.parse | |
def cookieManager = new CookieManager(null, CookiePolicy.ACCEPT_ALL) | |
CookieHandler.setDefault(cookieManager) | |
def doc = parse( | |
new URL('https://www.packtpub.com/packt/offers/free-learning').text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;;; | |
;;; Author: Bahman Movaqar <Bahman AT BahmanM.com> | |
;;; | |
(require net/url) | |
(require sxml) | |
(require net/uri-codec) | |
(require net/http-client) | |
(require (planet neil/html-parsing)) | |
(require net/cookies) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Copyright Bahman Movaqar <Bahman AT BahmanM.com> | |
; Source -> https://github.com/bahmanm/touka/blob/master/misc.scm | |
; Tests -> https://github.com/bahmanm/touka/blob/master/tests/misc-tests.scm | |
;; 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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 |
NewerOlder