Skip to content

Instantly share code, notes, and snippets.

View youxiachai's full-sized avatar

youxiachai youxiachai

View GitHub Profile
@youxiachai
youxiachai / gist:4ba917796f972ca06526
Created March 25, 2015 02:06
获得viewpage 当前fragment 实例
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 July 19, 2014 02:14
简单模拟了一下 node 的事件类
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 July 8, 2014 06:29
express 中间件匹配用法..,注意位置!
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 June 30, 2014 08:35
js 各种黑科技写法
var x = {
a : 1,
b : 2,
c : 3
}
var y = {
b : 5
}
@youxiachai
youxiachai / retrunasync.js
Created June 17, 2014 08:45
嵌套async练习
var async = require('async');
async.eachSeries(['2m内容'], function (item, callback) {
async.parallel([
function (subcallback) {
//1
},
function (subcallback){
//2
@youxiachai
youxiachai / jsistrue.js
Last active August 29, 2015 14:02
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
@youxiachai
youxiachai / specic.txt
Created June 9, 2014 07:15
搞怪泰文
( ̄(工) ̄) 凸ส้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้
@youxiachai
youxiachai / jsarray.js
Created June 9, 2014 06:29
js 数组练习 2
/**
* Created by youxiachai on 14-6-9.
*/
var totalPoint = 0;
var action = ''
//rule
@youxiachai
youxiachai / megesort.js
Last active August 29, 2015 14:02
归并排序
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 June 1, 2014 08:51
不用循环构建任意初始值数组
var a = Array.apply(null, {length : 10}).map(function () {
return 'a'
})
var b = new Array(10).join(',').split(',').map(function(){return 'b'});