Skip to content

Instantly share code, notes, and snippets.

Avatar

youxiachai youxiachai

View GitHub Profile
@youxiachai
youxiachai / gist:4ba917796f972ca06526
Created Mar 25, 2015
获得viewpage 当前fragment 实例
View gist:4ba917796f972ca06526
FragmentManager fm = getSupportFragmentManager();
Class<FragmentStatePagerAdapter> viewPageAdpater = FragmentStatePagerAdapter.class;
try {
Field field = viewPageAdpater.getDeclaredField("mCurrentPrimaryItem");
field.setAccessible(true);
Fragment value = (FgmMyGameCircleList) field.get(FragmentStatePagerAdapter(实例));
@youxiachai
youxiachai / EventMain.java
Created Jul 19, 2014
简单模拟了一下 node 的事件类
View EventMain.java
public class EventMain {
public static class Emitter {
private ConcurrentMap<String, ConcurrentLinkedQueue<Listener>> mCallbacks = new ConcurrentHashMap<String, ConcurrentLinkedQueue<Listener>>();
private ConcurrentHashMap<Listener, Listener> mOnceCallback = new ConcurrentHashMap<Emitter.Listener, Emitter.Listener>();
public Emitter on(String event, Listener fn) {
@youxiachai
youxiachai / express.js
Created Jul 8, 2014
express 中间件匹配用法..,注意位置!
View express.js
app.use('/fsck', function (req, res, next){
console.log('fsck');
res.header("How-Old-Are-You", "Iamfinethinkyou");
next();
})
app.get('/fsck/fsck', function (res, res){
console.log('fsck');
res.send('ok')
@youxiachai
youxiachai / hackjs1.js
Created Jun 30, 2014
js 各种黑科技写法
View hackjs1.js
var x = {
a : 1,
b : 2,
c : 3
}
var y = {
b : 5
}
View retrunasync.js
var async = require('async');
async.eachSeries(['2m内容'], function (item, callback) {
async.parallel([
function (subcallback) {
//1
},
function (subcallback){
//2
@youxiachai
youxiachai / jsistrue.js
Last active Aug 29, 2015
js 真值练习
View jsistrue.js
console.log(undefined >= 0); // false
console.log(null === 0); // false
console.log(null == 0); // false
console.log(0 >= 0); // true
//坑来了.. 对了js只有恒等 只有 !==, === 可没有恒比较 >== 的写法.
// 直觉上 null >= 0 应该跟 null == 0 或者 undefined >= 0 的效果一样的啊..但是事实不是这样的..
console.log(null >= 0); //true
View specic.txt
( ̄(工) ̄) 凸ส้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้
@youxiachai
youxiachai / jsarray.js
Created Jun 9, 2014
js 数组练习 2
View jsarray.js
/**
* Created by youxiachai on 14-6-9.
*/
var totalPoint = 0;
var action = ''
//rule
@youxiachai
youxiachai / megesort.js
Last active Aug 29, 2015
归并排序
View megesort.js
Array.prototype.mergeSort=function(){
var merge=function(left,right){
var final=[];
while (left.length && right.length) {
final.push(left[0] <= right[0] ? left.shift() : right.shift() );
}
return final.concat(left.concat(right));
}
// 递归结束
if (this.length < 2) {
@youxiachai
youxiachai / array2.js
Created Jun 1, 2014
不用循环构建任意初始值数组
View array2.js
var a = Array.apply(null, {length : 10}).map(function () {
return 'a'
})
var b = new Array(10).join(',').split(',').map(function(){return 'b'});