Skip to content

Instantly share code, notes, and snippets.

@gockxml
gockxml / gist:7276898
Created November 2, 2013 08:47
Implement `store` and `inspect` for chain operation in Javascript.
var cache = []
[1,2,3,4].map(function(i){
return i * 2
})
.inspect() // log intermediate value [2,4,6,8]
.store(cache) // store intermediate value [2,4,6,8] in cache variable
.reverse() // [8,6,4,2]
.filter(function(i, k){
return i >= cache[k]
@gockxml
gockxml / bind_select.sj
Created November 26, 2012 09:25
bind_select
function bind_select(first, second, data){
var change = function(evt){
var first_elem = $(first)[0];
var second_elem = $(second);
second_elem.html("");
second_elem = second_elem[0]
values = data[first_elem.value]
for (var i=0, len = values.length; i < len; i++){
if (!(values[i] instanceof Array)){
values[i] = [values[i]]
@gockxml
gockxml / bind_ajax_update.js
Created November 26, 2012 09:24
bind_ajax_update
function bind_ajax_update(selector, until, interval, get_status, callback){
var filters = []
interval = interval || 5000
for (var i in until){
filters.push("[status=" + until[i] + "]")
}
var ajax_update = function(elem){
var $elem = $(elem)
var url = $elem.attr("data-url")
console.log("ajax update")
@gockxml
gockxml / A.CPP
Created November 2, 2012 07:13 — forked from anonymous/A.CPP
熊锋求大神!
// XF_FLT_OMPDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "XF_FLT_OMP.h"
#include "XF_FLT_OMPDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@gockxml
gockxml / gist:3488007
Created August 27, 2012 12:28
generate random-like id
import math
def generate(id, align = 8):
a = bin(id)[2:]
bin_align = int(math.log(10 ** align, 2))
fill_a = a.rjust(bin_align, '0')
left = fill_a[: bin_align / 2]
right = fill_a[bin_align / 2:]
temp = [int(right[-1])]
for i in right[::-1][1:]: