Skip to content

Instantly share code, notes, and snippets.

View coderek's full-sized avatar
👽

Derek Zeng coderek

👽
View GitHub Profile
@coderek
coderek / MiddlewarePattern.js
Created July 25, 2014 02:02 — forked from tastywheat/taskQueue.js
simple demonstration. this pattern is used by connect to stack middlewares
//process n number of async functions in order. used when promises aren't viable e.g. cross file or service calls.
var MiddlewareService = function(){
var stack = [],
isProcessingStack = false,
commonState = { task: 0 };
function push(fn){
stack.push(fn);
@coderek
coderek / mraid.html
Created July 31, 2014 01:12
mraid sample
<script src="mraid.js"></script>
<!--april 1--><head>
<meta name="viewport" content="width=device-width, user-scalable=no">
</head>
<script>if (!window.mraid) { document.write('<script src="http://cdn.engagefront.com/mraid-basic.js"><\/script>'); }</script>
<script>
!function(a){a.setTimeout(function(){var b=a.document,c="engagefront",d="/EngageMetrics/v1/",e="script",f=b.getElementsByTagName(e)[0],g=b.createElement(e),h=b.location,i=h.protocol;g.src="https:"===i?"https://"+c+"-a.akamaihd.net"+d:"http://cdn."+c+".com"+d,f.parentNode.insertBefore(g,f)},0)}(window);
</script>
<style>
String.prototype.hashCode = function() {
var hash = 0, i, chr, len;
if (this.length == 0) return hash;
for (i = 0, len = this.length; i < len; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
_, seq = STDIN.read.scan(/(\n>THREE[^\n]*\n)([^>]*)\n/).flatten
p _, seq
# you can run this file as `ruby scan.rb < test`, where test contains the text to match
# it matches something like this, note the new line at beginning
#
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0Gws3wF4N6Yzm6nAXg4ub7InIpYqUm4j/1N1HOIcxfblr2kS9NZ8dHUdZMVhCjHvkrEpExH9OdFjTVzbfYtMNvX8XOCOglosdTrGXwJrO3vg5Emz9ntu6DXgA26SxMi7dQnKjZKPxi6e7+Tx82BC62pAmr/nrVQTOM6fa+682KwEmk4ONXXcc8WObiC3Lk8AEbDS9WTB+ejcKTwRH4lMX5OFyZ1aEux8PL35Iu4hIU7fwSn8zspnuCLyEyhLElPAg3e7k2wxd/9rySPPKntYzZ4YnhUNC+E6JTEhhRlbXpWL8O54xph+bs8GG5kjyGDzZK3vUU7ue/c+Fh8Kr4nAZ [email protected]
class Solution:
# @param board, a 2D array
# Capture all regions by modifying the input board in-place.
# Do not return any value.
def solve(self, b):
if len(b) == 0:
return []
board = [list(x) for x in b]
allEntrances = self.findAllEntrances(board)
var log = console.log.bind(console);
/**
* Given a ad
* calculate max bid rate
*/
function calculate_max_bid_rate(ad) {
var org_chain = get_org_chain(ad);
/**
* get remaining time
* @param {string} start - UTC/ISO time string
* @param {string} end - UTC/ISO time string
*/
function getRemainingTime(start, end) {
start = moment(start), end = moment(end);
var now = moment();
if (now > end) {
@coderek
coderek / filter_collectionview.js
Last active November 17, 2018 10:08
Implement filter collectionview for marionette
/**
* matchFilter
* @param {Object} term - key:val pairs that model need to match
* @returns {boolean}
*/
Backbone.Model.prototype.matchFilter = function (conditions) {
return _.every(conditions, function (val, key) {
return this.get(key) === val;
}, this);
@coderek
coderek / vimrc
Last active January 1, 2021 00:57
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim/
let path='~/vimfiles/bundle'
call vundle#begin(path)