Skip to content

Instantly share code, notes, and snippets.

@DadgadCafe
DadgadCafe / with.js
Created March 30, 2017 11:11
notes about with statement.
const obj = {
x: 10,
foo: function foo () {
function bar () {
console.log(x) // undefined, scope foo
console.log(y) // 30, scope bar
console.log(this.x) // 20
console.log(this.y) // undefined
}
@DadgadCafe
DadgadCafe / koa2middleware.js
Created April 2, 2017 08:50
chaining async flow, like in koa2.
// must return or await next() in koa2, otherwise promise chain will be terminated.
const delay = () => new Promise(resolve => {
console.log('delay...')
setTimeout(() => {
resolve()
}, 1000)
})
@DadgadCafe
DadgadCafe / for-clojure.cljs
Created April 10, 2017 14:39
notes of problem on 4clojure
;;;;;;;;;; Last Element
;; (= (__ [1 2 3 4 5]) 5)
;; (= (__ '(5 4 3)) 3)
;; (= (__ ["b" "c" "d"]) "d")
#(nth % (- (count %) 1))
#(nth % (dec (count %)))
;;;;;;;;;; Penultimate Element
;; (= (__ (list 1 2 3 4 5)) 4)
@DadgadCafe
DadgadCafe / clojurescript-unraveled.md
Last active April 20, 2017 08:15
translation draft.

1. 关于此书

本书涵盖了 ClojureScript 编程语言,可作为其开发工具的详细指南,并提供了一系列适用于 ClojureScript 日常编程的主题文章。

这不是一本入门编程的书,它假定读者至少有一种语言的编程经验。不过,并不要求有 Clojure 或者函数式编程经验。当谈到一些不是人尽皆知的 ClojureScript 理论基础时,我们会尝试给出参考材料的链接。

ClojureScript 文档虽很好但太过松散,因此我们想写一个参考资料的纲要,并提供全面的示例,作为 ClojureScript 的入门书和实用指南。本文档作为语言特性的参考和实战的手册,会随着 ClojureScript 语言更新。

本书将非常适合你,如果:

@DadgadCafe
DadgadCafe / HPFFP.md
Last active November 3, 2022 10:49
Haskell Programming From First Principles

HASKELL PROGRAMMING FROM FIRST PRINCIPLES

CHAPTER1. ALL YOU NEED IS LAMBDA

1.1 All You Need is Lambda

lambda calculus:

computation model, 1930s, Alonzo Church, formalizing a method, Turing machines

-- lambda
data Term = Lam Var Term
| Var Var
| App Term Term -- func application
data Var = V String
instance Show Var where
show (V s) = s
I ii iii IV V vi vii'
i ii' IIIb iv v VIb VIIb
II7 III7 Vb7 VI7
IIb
?: iib iiib vb vib viib vii VII
# naming conventions:
# module_name, package_name, method_name, function_name, global_var_name, instance_var_name, function_parameter_name, local_var_name
# ClassName, ExceptionName
# GLOBAL_CONSTANT_NAME
*a = *range(3), #(1, 2, 3)
#################
# http://sahandsaba.com/thirty-python-language-features-and-tricks-you-may-not-know.html
@DadgadCafe
DadgadCafe / promise.py
Created June 22, 2017 15:10
naive async flow like node, using promise
import signal
# broken in eventloop things
class Promise:
def __init__(self, f):
self.status = 'PENDING'
self.cb = None
f(self.__resolve)
def resolve(v):
@DadgadCafe
DadgadCafe / unfair_coin.py
Created June 23, 2017 05:02
some algorithm...
# http://sahandsaba.com/interview-question-groupon-probability.html
import random
def bernoulli_process(p):
if p > 1.0 or p < 0.0:
raise ValueError("p should be between 0.0 and 1.0.")
while True:
yield random.random() > p
def von_neumann_extractor(process):