Skip to content

Instantly share code, notes, and snippets.

View zjhmale's full-sized avatar
🏠
Working from home

xxx zjhmale

🏠
Working from home
View GitHub Profile
@zjhmale
zjhmale / Makefile
Last active August 29, 2015 14:20 — forked from Arachnid/Makefile
include $(GOROOT)/src/Make.$(GOARCH)
TARG=kademlia
GOFILES=\
nodeid.go\
routingtable.go\
contact.go\
kademlia.go
include $(GOROOT)/src/Make.pkg

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

@zjhmale
zjhmale / hi_reddit.go
Last active August 29, 2015 14:20 — forked from rafkhan/hi_reddit.go
package main
import (
"fmt"
"reflect"
)
//function types
type mapf func(interface{}) interface{}
@zjhmale
zjhmale / scala option monad
Last active August 29, 2015 14:21
scala option map filter
val a : Option[String] = Some("333")
//a: Option[String] = Some(333)
a.filter(_.length > 1).map(_.length)
//Option[Int] = Some(3)
a.filter(_.length > 6).map(_.length)
//Option[Int] = None
//filter and map function is just for Option type it's just a monad
//def filter(p: A => Boolean): Option[A]
//def map[B](f: A => B): Option[B]

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

@zjhmale
zjhmale / mongo-operation
Last active August 29, 2015 14:22
raw mongo snippets
db.tabclicktime.update(
{tabid: 8},
{$set: {title: "电视剧"}},
{multi: true}
);
//-1 -> desc 1 -> asc
db.tabclicktime.find({tabid: 8}).sort({timestamp: -1})
@zjhmale
zjhmale / 1-fundation
Last active September 8, 2015 04:17
something about clojure macro
(let [expression (read-string "(+ 1 2 3 4 5)")]
(cons (read-string "*")
(rest expression)))
;;=> (* 1 2 3 4 5)
(eval *1)
;;=> 120
(let [expression '(+ 1 2 3 4 5)]
(cons '* (rest expression)))
;;
;; 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.
@zjhmale
zjhmale / hof
Created June 26, 2015 08:11
write elegant and concise code use high order function in clojure
;;fp语言之所以有抽象能力或者说非fp语言是告诉机器如何一步一步解决问题 而fp语言是向机器描述问题 然后让机器给我们答案其中一个语言原语就是高阶函数 也就是函数可以被当做参数和返回值 还有闭包的存在 函数不再是对象的附属 而是独立的个体 甚至LC中 只有单参函数这一个基本元素却能做到图灵完备 正所谓大道至简
@zjhmale
zjhmale / fizzbuzz.clj
Last active August 29, 2015 14:23 — forked from gigasquid/fizzbuzz.clj
(defn fizzbuzz [n]
(let [all-nums (range 0 n)
folder (fn [fb-str p-num fb-coll]
(mapcat (fn [x] (cons fb-str (rest x)))
(partition-all p-num fb-coll)))
fizz (folder "fizz" 3 all-nums)
buzz (folder "buzz" 5 fizz)
fizzbuzz (folder "fizzbuzz" 15 buzz)]
fizzbuzz))