Skip to content

Instantly share code, notes, and snippets.

View HeGanjie's full-sized avatar

Bruce He HeGanjie

View GitHub Profile
# https://unix.stackexchange.com/questions/10428/simple-way-to-create-a-tunnel-from-one-local-port-to-another
ssh -L -R # limit for 0.0.0.0
watch -n0 busybox nc -l -p 3389 -e /bin/nc 127.0.0.1 8000 # have restart time gap
socat tcp-listen:443,reuseaddr,fork tcp:localhost:8080 # need install
# can not install socat, compile yourself? https://github.com/cornerpirate/socat-shell
@HeGanjie
HeGanjie / a.sh
Created April 23, 2018 02:50
quick run typescript
npx -p typescript -p ts-node -c "nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/server/app.ts"
debug:
npm i ts-node --no-save
npx -p typescript -p ts-node -c 'node -r ts-node/register --inspect-brk src/server/app.ts'
npx webpack --progress
@HeGanjie
HeGanjie / app.js
Last active February 1, 2018 10:32
Lite http dynamic proxy in js
// https://imququ.com/post/web-proxy.html
// test cmd:
// curl --proxytunnel -x http://localhost:8000 --proxy-basic --proxy-user a:b httpbin.org/get
var http = require('http')
var net = require('net')
var url = require('url')
function connect(cReq, cSock) {
let u = url.parse('http://' + cReq.url)
import React from 'react'
import * as d3 from 'd3'
export default class CircularProgress extends React.Component {
constructor(props) {
super(props);
this.state = {
aProgress: props.min
}
[user]
email = heganjie@gmail.com
name = heganjie
[gui]
encoding = utf-8
[branch]
autosetupmerge = always
[alias]
aa = add -A
st = status

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);
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
@HeGanjie
HeGanjie / build.gradle
Created June 5, 2014 15:42
compile android using java8
// 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 {
@HeGanjie
HeGanjie / _vimrc
Last active August 29, 2015 14:00
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
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);
}