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
View GitHub Profile
#!/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.
"""
@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
@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 / 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 / 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 / awsFile.js
Last active August 12, 2017 23:54
aws ec2 nodejs
var AWS = require('aws-sdk');
AWS.config.loadFromPath('./config.json');
AWS.config.region = 'ap-southeast-1';
//1. download
// var s3 = new AWS.S3();
// var file = require('fs').createWriteStream('./docConv.html');
// var params = {Bucket: 'bpctest', Key: 'docConv.html'};
@bpceee
bpceee / qcUpdateRouter.python
Last active August 29, 2015 14:06
qingcloud update router
import qingcloud.iaas
from qingcloud.iaas.router_static import RouterStaticFactory
access_key = 'xxx'
secret_key = 'xxx'
conn = qingcloud.iaas.connect_to_zone('gd1', access_key, secret_key)
router = 'rtr-xxxxxxxx'
# add port forwarding static
@bpceee
bpceee / azurecros.js
Last active August 29, 2015 14:07
set azure cros
var crypto = require('crypto');
var request = require('request');
var setCors = function (MY_ACCOUNT_URL, MY_ACCOUNT_NAME, accountKey) {
var MY_CORS_XML =
'<?xml version="1.0" encoding="utf-8"?>'+
'<StorageServiceProperties>'+
'<Cors>'+
'<CorsRule>'+
@bpceee
bpceee / partialfun.js
Created October 15, 2014 03:51
partial function
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))
}
}
@bpceee
bpceee / gist:0a58e4148e296439b255
Created July 26, 2015 14:14
calculate the SVG Path for an arc (of a circle)
http://stackoverflow.com/questions/5736398/how-to-calculate-the-svg-path-for-an-arc-of-a-circle
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
var angleInRadians = angleInDegrees * Math.PI / 180.0;
var x = centerX + radius * Math.cos(angleInRadians);
var y = centerY + radius * Math.sin(angleInRadians);
return [x,y];
}