Skip to content

Instantly share code, notes, and snippets.

View bpceee's full-sized avatar
💭
In meditation

Ken Bi bpceee

💭
In meditation
  • Auckland, New Zealand
  • 23:03 (UTC +12:00)
View GitHub Profile
@bpceee
bpceee / demo.js
Last active January 27, 2022 15:42
optimistic lock implementation in mongodb
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var ThingSchema = new mongoose.Schema({
count: Number,
version: Number,
});
var Thing = mongoose.model('Thing', ThingSchema);
var doAdd = function(id, retryTimes){
@bpceee
bpceee / lock.js
Created August 11, 2014 02:24
pessimistic lock in nodejs
function partial(f) {
var args = Array.prototype.slice.call(arguments, 1)
return function() {
var remainingArgs = Array.prototype.slice.call(arguments)
return f.apply(null, args.concat(remainingArgs))
}
}
var options = {
db: {
@bpceee
bpceee / daterange.py
Created June 22, 2014 13:36
date iteration
#!/usr/bin/env python
# coding=utf-8
from datetime import datetime, timedelta
def daterange(start, stop, step_minutes=1):
current = start
step = timedelta(minutes=step_minutes)
if step_minutes > 0:
while current < stop:
@bpceee
bpceee / install_nginx.sh
Last active August 29, 2015 14:00 — forked from simonw/gist:92481
Compile nginx standalone without root access
# Compile nginx standalone without root access
mkdir ~/installed
mkdir ~/installed/nginx
mkdir ~/src
cd ~/src
# PCRE dependency - we'll compile against this statically
wget http://kent.dl.sourceforge.net/sourceforge/pcre/pcre-7.8.tar.gz
tar -xzvf pcre-7.8.tar.gz
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""