Skip to content

Instantly share code, notes, and snippets.

View t1anchen's full-sized avatar

tianchen t1anchen

View GitHub Profile
@t1anchen
t1anchen / gist:7249422
Last active December 27, 2015 01:59
maplist
;; Leiningen 2.3.2
;; Clojure 1.5.1
;; REPL
;;
(defn maplist [f coll] (map #(apply f %) (take (count coll) (iterate rest coll))))
(maplist min (range 10))
;; (0 1 2 3 4 5 6 7 8 9)
(maplist max (range 10))
;; (9 9 9 9 9 9 9 9 9 9)
(maplist * (range 1 11))
@t1anchen
t1anchen / gist:7305345
Created November 4, 2013 16:37
factorial
;; Take k-th product while n!(n-1)!...(n-k+1)!...2!1!
;;
(map (fn [x] (reduce * x)) (take 10 (iterate rest (range 10 0 -1))))
;; (3628800 362880 40320 5040 720 120 24 6 2 1)
(reduce *' (map (fn [x] (reduce *' x)) (take 10 (iterate rest (range 10 0 -1)))))
;; 6658606584104736522240000000N
@t1anchen
t1anchen / GetLines.scala
Created November 21, 2013 16:29
jar package manually
import scala.collection.mutable.BitSet
import scala.collection.mutable.Map
// Don't learn this code!
// Ugly implementation!
object GetLines {
def main(args: Array[String]) {
if (args.length < 1) {
println("Please specify the file to count")
return
@t1anchen
t1anchen / douban.math.js
Created December 29, 2013 11:52
Display Mathjax expression (including LaTeX and MathML) in the trivial web page
// ==UserScript==
// @name mathjax for douban
// @namespace [email protected]
// @author Changsheng Jiang<[email protected]> // 感谢原作者,并且我把math_jax_src改回原来的mathjax.org了
// @include http://*.douban.com/*
// @description texify formula using mathjax
// @date 2011-07-12
// @version 20110712
// ==/UserScript==
@t1anchen
t1anchen / DummyInterview001.java
Created January 1, 2014 07:44
Dummy Interview Problems
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.*;
/**
* Dummy Interview 1: Sorting
* --------------------------
@t1anchen
t1anchen / timer.sh
Last active August 29, 2015 13:56
Timer
#!/bin/sh
read -p "Play? " op
while [ "$op" != "n" ]
do
touch timerflag1
echo "Started ..."
@t1anchen
t1anchen / build.scala
Last active August 29, 2015 14:00
ant task for validating and packaging videos with proper-size data block
val fs = (new java.io.File(".")).listFiles.filter(x => x.getName.contains("asc"))
val ctx = fs.map(x => (x.getName.replace(".asc",""),scala.io.Source.fromFile(x).getLines.next))
ctx.map(i => {
val x = i._1
val y = i._2
val orig = new java.io.File(x)
val suffix = orig.getName.split('.').last
val newf = new java.io.File(y+"."+suffix)
orig.renameTo(newf)
@t1anchen
t1anchen / yml_format.py
Created May 30, 2014 13:06
check manual yaml file and re-format it to formulized one
#!/usr/bin/python
import sys
import yaml
def main():
"""check.py: a simple tool to check yaml format
Usage: check.py <yaml_filename>
"""
mode = 'piped'

Keybase proof

I hereby claim:

  • I am t1anchen on github.
  • I am tianchen (https://keybase.io/tianchen) on keybase.
  • I have a public key ASCK4l9DOItIvwAUnsQgSrGuOeGvR-F4qgMFSn6r2rSNOwo

To claim this, I am signing this object:

@t1anchen
t1anchen / init.el
Created January 17, 2024 17:07
Mitigation to Paredit minor mode overrides RET behaviour in geiser major mode
(add-hook
'geiser-repl-mode-hook
#'(lambda ()
(paredit-mode 1)
;; RET is bound to geiser-repl-maybe-send in geiser mode
(define-key paredit-mode-map (kbd "RET") nil))