Skip to content

Instantly share code, notes, and snippets.

View HeGanjie's full-sized avatar

Bruce He HeGanjie

View GitHub Profile
@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
}
.flex {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.flex.flex--reverse {
-webkit-box-orient: horizontal;
@HeGanjie
HeGanjie / Drag PNG here.bat
Created September 12, 2014 01:29
bat for pngquant, auto cover original png file (DANGEROUS)
:: http://pngquant.org/
@echo off
set path=%~d0%~p0
:start
"%path%pngquant.exe" --force --ext .png --verbose --ordered --speed=1 --quality=50-90 %1

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);
[user]
email = [email protected]
name = heganjie
[gui]
encoding = utf-8
[branch]
autosetupmerge = always
[alias]
aa = add -A
st = status
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);
}