Skip to content

Instantly share code, notes, and snippets.

@bolasblack
bolasblack / post-receive
Created December 1, 2014 03:48
auto checkout last pushed commit
#!/bin/bash
while read oldrev newrev ref; do
result=$(GIT_WORK_TREE=/path/to/deploy/repo git checkout -f $newrev)
if [ $? -eq 0 ]; then
echo 'Deploy Success!'
else
echo $result
fi
done
@bolasblack
bolasblack / querystirng-parser.coffee
Last active August 29, 2015 14:13
Parse querystring
params = (search = location.search) ->
RE = /(\?|&)([^=&]+)(=([^&$]*))?(?=&|$)/
matches = search.match RegExp RE.source, 'g'
return {} unless matches
matches.reduce (memo, elem) ->
matchParts = elem.match RE
value = matchParts[4]
# if value is '' or undefined, keep it
@bolasblack
bolasblack / sentry.init
Last active August 29, 2015 14:13
Simple gentoo run-script for sentry
#!/sbin/runscript
extra_commands="debug"
SENTRY_COMMAND="/home/sentry/sentry-env/bin/sentry"
SENTRY_CONFILE=/home/sentry/sentry.conf.py
SENTRY_USER=sentry
SENTRY_PIDFILE=/var/run/sentry.pid
SENTRY_LOGFILE=/home/sentry/sentry.log
@bolasblack
bolasblack / ocserv.init
Last active June 11, 2020 14:53
/etc/init.d/ocserv
#!/sbin/runscript
DAEMON=/usr/local/sbin/ocserv
PIDFILE=/var/run/ocserv.pid
LOGFILE=/var/log/ocserv.log
DAEMON_ARGS="-f -d 1"
extra_commands="debug"
depend() {
> ~ $ echo '{"ni":1}' | LANG=en_US.utf-8 python -c 'import json, sys; print json.dumps(sys.stdin.read())'
"{\"ni\":1}\n"
> ~ $ echo '{"ni":1}' | LANG=en_US.utf-8 python -c 'import json, sys; print json.dumps(json.loads(sys.stdin.read()), indent=2, separators=(",", ": "))'
{
"ni": 1
}
server {
listen 80;
server_name ci.server.name;
ignore_invalid_headers off;
access_log /var/log/nginx/jenkins.access_log main;
error_log /var/log/nginx/jenkins.error_log info;
location / {
@bolasblack
bolasblack / unicode_json_stringify.coffee
Created April 10, 2015 15:44
Drop-in replacement for JSON. `JSON.stringify` return unicodified content. **Not support chrome**
originJSON = window.JSON or global.JSON
JSON = {
parse: (-> originJSON.parse.apply originJSON, arguments)
# http://stackoverflow.com/a/4901205
stringify: (obj, replacer, space) ->
unicodeRE = /[\u007f-\uffff]/g
# 如果直接在 JSON.stringify 的 replacer 里面加 '\\u' ,结果会真的被 JSON
# 替换为 \\u ,最终输出的结果就是 {"a": "\\u007f"} ,所以需要在得到 json 以
@bolasblack
bolasblack / AppDelegate.m
Last active August 29, 2015 14:20
React-native with coffee
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "AppDelegate.h"
@bolasblack
bolasblack / Vagrantfile
Created June 24, 2015 09:18
Vagrantfile to auto install nodejs
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@bolasblack
bolasblack / export.scpt
Last active September 10, 2018 09:14
Export OS X Reminder
on format_time(currTime as date)
set stamp to the time of currTime
set h to text -2 thru -1 of ("00" & (stamp div (60 * 60)))
set m to text -2 thru -1 of ("00" & (stamp - (60 * 60) * h) div 60)
set s to text -2 thru -1 of ("00" & (stamp - ((60 * 60) * h + 60 * m)))
return h & ":" & m & ":" & s
end format_time
-- from http://henrysmac.org/blog/2014/1/4/formatting-short-dates-in-applescript.html
on format_date(currTime as date)