Skip to content

Instantly share code, notes, and snippets.

@plcgi1
plcgi1 / gist:033551557d942a61c98309354effa03e
Created September 13, 2016 17:56
Example async.retry
var async = require('async');
var apiMethod = function(callback) {
console.info('apiMethod.arguments', callback);
// callback returns error
return callback(123);
// callback return ok
return callback(123);
}
(function(document, $, angular) {
var app = angular.module('inklocker.directives');
/* @description
* Usage:
*
*
*
*
* */
// http://momentjs.com/docs/#/query/is-between/
// Version 2.13.0 introduces inclusivity.
// A [ indicates inclusion of a value. A ( indicates exclusion.
// If the inclusivity parameter is used, both indicators must be passed.
moment('2016-10-30').isBetween('2016-10-30', '2016-12-30', null, '()'); //false
moment('2016-10-30').isBetween('2016-10-30', '2016-12-30', null, '[)'); //true
moment('2016-10-30').isBetween('2016-01-01', '2016-10-30', null, '()'); //false
moment('2016-10-30').isBetween('2016-01-01', '2016-10-30', null, '(]'); //true
moment('2016-10-30').isBetween('2016-10-30', '2016-10-30', null, '[]'); //true
@plcgi1
plcgi1 / async.parallel
Last active March 17, 2017 18:07
nodejs async paralles usage template
var async = require('async');
_ = require('lodash');
var DATA = [
{ id: 1, name: 'One', group: 'One' },
{ id: 4, name: 'Trr', group: 'Two' },
{ id: 3, name: 'Rtt', group: 'Three' },
{ id: 4, name: 'Vbb', group: 'Two' },
{ id: 8, name: 'Ncc', group: 'One' },
{ id: 6, name: 'Onaaa', group: 'Three' },
// http://fastcodenote.blogspot.com.by/2013/09/nodejs-async.html
var async = require('async');
_ = require('lodash');
var DATA = [
{ id: 1, name: 'One', group: 'One' },
{ id: 2, name: 'Trr', group: 'Two' },
{ id: 3, name: 'Rtt', group: 'Three' },
{ id: 4, name: 'Vbb', group: 'Two' },
{ id: 5, name: 'Ncc', group: 'One' },
app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
var r = 480,
format = d3.format(",d"),
fill = d3.scale.category20c();
var keeper;
var bubble = d3.layout.pack()
.sort(null)
.size([r, r]);
@plcgi1
plcgi1 / image-service.js
Created June 9, 2016 18:05 — forked from transitive-bullshit/image-service.js
Angular service to resize images with antialiasing for use with canvas.
angular.module('demo').service('imageService', function ($http, $q, $timeout) {
var NUM_LOBES = 3
var lanczos = lanczosGenerator(NUM_LOBES)
// resize via lanczos-sinc convolution
this.resize = function (img, width, height) {
var self = { }
self.type = "image/png"
self.quality = 1.0
var WebSocketServer = require('ws').Server
, http = require('http')
, express = require('express')
, path = require('path')
, net = require('net')
, app = express()
, adb = require('adbkit')
, childProcess = require('child_process')
, json = require('JSON')
, fs = require('fs')
package Fake::Component::Node;
use strict;
use utf8;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(qw/max/);
sub get_current_row_data {
my ($self,$id) = @_;
my $i = 0;
return { row => 1 } unless $id;