Skip to content

Instantly share code, notes, and snippets.

Avatar

Bruce He HeGanjie

View GitHub Profile
@HeGanjie
HeGanjie / recur.clj
Last active Oct 3, 2021
CPS can't reduce the time complexity...
View recur.clj
;fac
(defn fac [n]
(if (zero? n) 1
(* n (fac (dec n)))))
(defn fac-t [n acc] ; n 1
(if (zero? n) acc
(recur (dec n) (* acc n))))
(defn fac-c [n f] ; n identity
View stream-in-ruby.md

Stream是一种能容纳无穷对象的容器,我在研究了Js的实现后,尝试用Ruby实现一下。另外加上阶乘数列和 费波纳茨数列的实现。
Stream.js的介绍: http://www.aqee.net/stream-javascript-lib/
Stream的详情请参考: http://www.aqee.net/docs/stream/

class Stream
	def initialize(head = nil, tail = nil)
		@head = head
		@tailFunc = tail
	end
View YCombinator.md

在LISP之根源里面看到作者提到Y组合子,于是去了解了一下,但是看其他人的解释都很难完全弄懂。
最后通过 王垠的wiki 发现 Franco 教授的推演过程讲得最简单易懂,在看懂了之后我再用CoffeeScript推演了一次,加深理解。

LISP之根源 http://daiyuwen.freeshell.org/gb/rol/roots_of_lisp.html#foot108
王垠的wiki http://minus273.eu/mirrors/2001315450/wiki/SchemeYcombinator.html
Franco 教授的推演过程 http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html
可以将代码贴在这里上面验证结果 http://coffeescript.org/

  • 第一步
View androidUtils.md
public static float dp2Px(float dp, Context context){
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return dp * (metrics.densityDpi / 160f);
}

public static float px2Dp(float px, Context context) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return px / (metrics.densityDpi / 160f);
}
View _vimrc
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
@HeGanjie
HeGanjie / build.gradle
Created Jun 5, 2014
compile android using java8
View build.gradle
// http://www.cnblogs.com/youxilua/archive/2013/05/20/3087935.html
// https://github.com/evant/gradle-retrolambda
// http://tools.android.com/tech-docs/new-build-system/user-guide
buildscript {
repositories {
mavenCentral()
}
dependencies {
View gradleAndroidBase.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
View .gitconfig
[user]
email = heganjie@gmail.com
name = heganjie
[gui]
encoding = utf-8
[branch]
autosetupmerge = always
[alias]
aa = add -A
st = status
View JavaStringIgnoreCase.md

Java/Android case insensitive contains and indexOf
O(n), no Object creating, no GC, should be faster than Pattern.CASE_INSENSITIVE?

public static boolean equalsIgnoreCaseInString(String longer, int ai, String shorter, int bi) {
	int chkLen = shorter.length() - bi;
	if (longer.length() - ai < chkLen) return false;
	for (int c = 0; c < chkLen; ai++, bi++, c++) {
		char ac = longer.charAt(ai);
		char bc = shorter.charAt(bi);
@HeGanjie
HeGanjie / Drag PNG here.bat
Created Sep 12, 2014
bat for pngquant, auto cover original png file (DANGEROUS)
View Drag PNG here.bat
:: http://pngquant.org/
@echo off
set path=%~d0%~p0
:start
"%path%pngquant.exe" --force --ext .png --verbose --ordered --speed=1 --quality=50-90 %1