Skip to content

Instantly share code, notes, and snippets.

@guileen
guileen / crc16.js
Created January 7, 2014 07:44
crc16
exports.crc16 = function (buffer, len) {
var crc = 0xffff;
for (var i = 0; i < len; i++) {
crc = ((crc ^ buffer[i]) & 0x00ff) + (crc & 0xff00);
for (var bit = 0; bit < 8; bit++) {
if ((crc & 0x0001) === 0x0000) {
crc >>= 1;
}
else {
crc >>= 1;

Google Speech To Text API

Base URL: https://www.google.com/speech-api/v1/recognize
It accepts POST requests with voice file encoded in FLAC format, and query parameters for control.

Query Parameters

client
The client's name you're connecting from. For spoofing purposes, let's use chromium

lang
Speech language, for example, ar-QA for Qatari Arabic, or en-US for U.S. English

@guileen
guileen / monitrc
Created January 25, 2013 15:02 — forked from metakeule/monitrc
# /etc/monit/monitrc (excerpt)
check process node-app with pidfile /var/run/node-app.pid
start program = "/sbin/start node-app" with timeout 5 seconds
stop program = "/sbin/stop node-app"
if failed port 3000 protocol HTTP
request /
with timeout 3 seconds
then restart
if cpu > 80% for 10 cycles then restart
import re
import json
import urllib
import base64
import hashlib
import requests
WBCLIENT = 'ssologin.js(v.1.3.18)'
sha1 = lambda x: hashlib.sha1(x).hexdigest()
@guileen
guileen / nginx.conf
Created July 24, 2012 05:09 — forked from srpouyet/nginx.conf
Nginx Upstart script (Ubuntu 12.04)
### Nginx upstart script
### source: http://serverfault.com/a/391737/70451
### /etc/init/nginx.conf
description "nginx http daemon"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/opt/nginx/sbin/nginx
@guileen
guileen / config.js
Created June 15, 2012 10:28
bad style?
// ------------
// config.js
module.exports = {mongo: 'mongo://localhost/test'};
// -----------
// index.js
var mongoskin = require('mongoskin');
@guileen
guileen / app.js
Created April 23, 2012 07:54
node benchmark
var http = require('http')
http.createServer(function(req, res) {
res.end('hello world');
}).listen('/tmp/test.sock');
@guileen
guileen / install-imagemagick.sh
Created April 13, 2012 07:31
install ImagMagick on ubuntu
# https://help.ubuntu.com/community/ImageMagick
sudo apt-get install imagemagick --fix-missing
# ignore below, just for information
# http://cn-popeye.iteye.com/blog/1236691
# install zlib
# page http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download?use_mirror=superb-dca2
@guileen
guileen / init-user-noshell.sh
Created April 12, 2012 09:13
create user for ssh no shell
# ensure you have nologin
#
# less /etc/shells
# which nologin
# /usr/sbin/nologin
# echo `which nologin` >> /etc/shells
useradd -m -s /usr/sbin/nologin public
# login without password
@guileen
guileen / init_user.sh
Created April 9, 2012 07:44
init user settings
#!/bin/bash
read -p "Please input username:" USERNAME
if [ ! -f "/bin/zsh" ]; then
apt-get install zsh
fi
useradd -U -s /bin/zsh -m $USERNAME
passwd $USERNAME