Skip to content

Instantly share code, notes, and snippets.

View mingyang91's full-sized avatar
🎯
Go for broke

Ming Yang mingyang91

🎯
Go for broke
View GitHub Profile
function testClosures() {
"use strict";
var result = [];
for (var var_index = 0; var_index < 2; var_index++) {
result.push(() => { return var_index; });
}
for (let let_index = 0; let_index < 2; let_index++) {
result.push(() => { return let_index; });
}
@mingyang91
mingyang91 / Lexicographic order.js
Last active September 30, 2015 07:51
next函数为求str字典序的下一项,lexicographic函数为求str字典序的第n项
"use strict";
function next (str) {
const charArr = str.split('');
const charReverseArr = charArr.reverse();
const inflectionIndex = charReverseArr.findIndex((element, index, array) => element < array[index - 1]);
const right = charReverseArr.slice(0, inflectionIndex);
@mingyang91
mingyang91 / Polynomial expansion.js
Created October 8, 2015 08:07
多项式展开(计算母函数系数)
/**
* 多项式相乘 [多项式1, 多项式2, 多项式3...]
* 多项式 {次数1: 系数1, 次数2: 系数2, ...}
*/
var simplePolynomials = [
{
0: 1,
1: 1,
2: 1,
3: 1,
@mingyang91
mingyang91 / miller-rabin.scm
Last active November 28, 2015 17:49
米勒-拉宾素性检验
#lang scheme
(define (square x) (* x x))
(define (gcd a b)
(if (= 0 b)
a
(gcd b (remainder a b))))
(define (expmod base exp m)
(cond ((= exp 0) 1)
@mingyang91
mingyang91 / 1.3.scm
Last active December 2, 2015 15:14
<SICP> 1.3
#lang scheme
(define (average . numbers)
(/ (apply + numbers) (length numbers)))
(define tolerance 0.000001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)
@mingyang91
mingyang91 / deriv.rkt
Last active March 1, 2016 09:45
<SICP> 2.3
#lang racket
(define variable? symbol?)
(define (same-variable? v1 v2)
(and (variable? v1) (variable? v2) (eq? v1 v2)))
(define (=number? exp num)
(and (number? exp) (= exp num)))

Keybase proof

I hereby claim:

  • I am mingyang91 on github.
  • I am famer (https://keybase.io/famer) on keybase.
  • I have a public key ASAcRGRvhvMiRo4EgLphpfDpKuYzf6vEdGhR6TOw1igV6go

To claim this, I am signing this object:

λ curl -X POST \
http://chouun.nadileaf.com/api/open-candidates/ \
-H 'authorization: Bearer <TOKEN>' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: 1c12fc65-c157-49c7-d9d4-d2ad10832c53' \
-d '
{
"openid": "b39fe420-d67e-11e7-a5de-0250bbe96648",
"industry":"互联网",
@mingyang91
mingyang91 / template code.scala
Created March 19, 2018 13:02
尝试移除模板代码
// utils
class FromJsonQueryStringBindable[T] ()(implicit decoder: Decoder[T],
encoder: Encoder[T]) extends QueryStringBindable[T] {
implicit val binder: QueryStringBindable[Json] = JsonQueryStringBindable
override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, T]] =
binder.bind(key, params).map(_.flatMap(_.as[T].left.map(_.message)))
override def unbind(key: String, value: T): String = s"$key=${value.asJson}"
}