Skip to content

Instantly share code, notes, and snippets.

@Unitecho
Unitecho / gist:5582824
Created May 15, 2013 09:45
Worker Thread pool JS
http://www.smartjava.org/content/html5-easily-parallelize-jobs-using-web-workers-and-threadpool
function Pool(size) {
var _this = this;
// set some defaults
this.taskQueue = [];
this.workerQueue = [];
this.poolSize = size;
@Unitecho
Unitecho / gist:5553150
Created May 10, 2013 08:22
Common Log streamers
var fs = require('fs');
var path = '/home/tknew/.forever/out-probe2.log';
var colors = [
'\x1B[34m',
'\x1B[36m',
'\x1B[32m',
'\x1B[35m',
'\x1B[31m',
@Unitecho
Unitecho / gist:5538511
Last active December 17, 2015 02:49
Combining forever and forever-monit
var foreverMonit = require('forever-monitor');
var forever = require('forever');
var child = new (foreverMonit.Monitor)('./toto.js', {
max: 3,
silent: false,
options: [],
sourceDir : '.',
pidFile : 'pid/app.pid'
});
@Unitecho
Unitecho / gist:5524604
Created May 6, 2013 11:27
Angular Notes

Angular Notes

module

  • requires
  • name
  • provider
  • factory
  • service
  • value
@Unitecho
Unitecho / gist:5524598
Created May 6, 2013 11:26
Angular - Promise $q
function asyncGreet(name) {
var deferred = $q.defer();
setTimeout(function() {
// since this fn executes async in a future turn of the event loop, we need to wrap
// our code into an $apply call so that the model changes are properly observed.
scope.$apply(function() {
if (okToGreet(name)) {
deferred.resolve('Hello, ' + name + '!');
} else {
@Unitecho
Unitecho / gist:5524591
Created May 6, 2013 11:25
Angular animation
- <div ng-directive ng-animate="{enter: 'animate-enter'}"></div>
- * .animate-enter-setup {
* -webkit-transition: 1s linear all; /&#42; Safari/Chrome &#42;/
* -moz-transition: 1s linear all; /&#42; Firefox &#42;/
* -ms-transition: 1s linear all; /&#42; IE10 &#42;/
* -o-transition: 1s linear all; /&#42; Opera &#42;/
* transition: 1s linear all; /&#42; Future Browsers &#42;/
*
* /&#42; The animation preparation code &#42;/
* opacity: 0;

Contract Killer 3

Revised date: 07/11/2012

Between us [company name] and you [customer name]

Summary:

We’ll always do our best to fulfil your needs and meet your expectations, but it’s important to have things written down so that we both know what’s what, who should do what and when, and what will happen if something goes wrong. In this contract you won’t find any complicated legal terms or long passages of unreadable text. We’ve no desire to trick you into signing something that you might later regret. What we do want is what’s best for both parties, now and in the future.

@Unitecho
Unitecho / gist:5393289
Created April 16, 2013 04:13
Intercept console.log output and write to file
var util = require('util');
var fs = require('fs');
var log = fs.createWriteStream('stdout.log');
console.log = console.info = function(t) {
var out;
if (t && ~t.indexOf('%')) {
out = util.format.apply(util, arguments);
process.stdout.write(out + '\n');
return;
var __ = require("../maki/lib/underscore.js");
var events = require("events");
var Stream = require('./events_caller.js').MyStream;
var stream = new Stream();
console.log(stream instanceof events.EventEmitter); // true
console.log(Stream.super_ === events.EventEmitter); // true
stream.on("data", function(data) {
@Unitecho
Unitecho / gist:5074920
Created March 3, 2013 06:21
google tts
rec -c 2 -r 16000 -s -t wav - | flac - -f --best --sample-rate 16000 -o out.flac
#arecord -f cd -t wav -d 5 -r 16000 | flac - -f --best --sample-rate 16000 -o out.flac
wget --post-file='out.flac' --header='Content-Type: audio/x-flac; rate=16000;' \
-O 'recognized.json' \
'https://www.google.com/speech-api/v1/recognize?lang=fr-FR'
ll