Skip to content

Instantly share code, notes, and snippets.

@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 以
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 / {
> ~ $ 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
}
@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() {
@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 / 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 / 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

Keybase proof

I hereby claim:

  • I am bolasblack on github.
  • I am c4605 (https://keybase.io/c4605) on keybase.
  • I have a public key whose fingerprint is EA86 3E37 3F20 BAD7 42BF A42A C704 6C4E 9F79 C1AB

To claim this, I am signing this object:

@bolasblack
bolasblack / -wrap-web-service-with-websocket
Last active August 29, 2015 14:08
wrap web service with websocket
nil
tell application "iTerm2"
activate
set windowCount to count of terminal windows
-- display dialog windowCount as text
if windowCount is 0 then
create window with default profile
delay 0.1