Skip to content

Instantly share code, notes, and snippets.

View nqbao's full-sized avatar
Make Stuff Works

Bao Nguyen nqbao

Make Stuff Works
View GitHub Profile
require "logstash/filters/base"
require "logstash/namespace"
#
# Filter plugin to normalize log levels from various logging frameworks
#
# The output field (log_level by default) will contain a number between
# 100 and 999, inclusive, with higher numbers indicating higher
# importance or severity.
#
/**
* American Express card numbers start with 34 or 37 and have 15 digits.
*/
'AMEX' => array(
'/^3[47][0-9]{13}$/'
),
/**
* China UnionPay cards start with 62 and have between 16 and 19 digits.
* Please note that these cards do not follow Luhn Algorithm as a checksum.
*/
if (current != null) {
Log.i("DEBUG", "top before: " + mProfileView.getTop());
current.cancel();
Log.i("DEBUG", "top after: " + mProfileView.getTop());
current = null;
}
pm = dynamic
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
@nqbao
nqbao / composer.json
Created June 20, 2014 02:52
Composer.json to icnlude both Symfony and Drupal in one setup
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"minimum-stability": "dev",
"autoload": {
"psr-0": { "": "src/", "SymfonyStandard": "app/" }
},
"require": {
# install ssh key on server
@task
def add_public_key(key_file="default.pub",key_type="openssh"):
with hide("running"):
key_abs_file = key_file
# 1st try
if not os.path.isfile(key_abs_file):
key_abs_file = os.getcwd() + "/" + key_file
if (self._minifyTogether) {
var sources = _.map(self.js, function (file) {
return file.contents('utf8');
});
buildmessage.enterJob({title: "minifying"}, function () {
allJs = _minify(minifiers.UglifyJS, '', sources, minifyOptions).code;
});
self.js = [new File({ info: 'minified js', data: new Buffer(allJs, 'utf8') })];
@nqbao
nqbao / gist:4931f4c7c102d5ae8dcf
Created August 16, 2015 04:23
Promise chaining example
// proof of concept for promise chaining
function chain(obj) {
let stack = [];
let proxy = new Proxy(obj, {
get: (target, name, receiver) => {
if (name == 'finally' || name == "done") {
return function(callback) {
return replayStack(obj, stack, callback);
}
@nqbao
nqbao / gist:e9cc34d3a2bb07eed505
Last active September 2, 2015 03:57
cancelable promise prototype
function cancellablePromise(executor) {
var deferred = Promise.defer();
var cancelled = false;
var promise = new Promise(executor).then(function(result) {
if (!cancelled) deferred.resolve();
else return arguments[0]
});
var actualPromise = Promise.all(deferred.promise, promise)
.then(function(result) {
@nqbao
nqbao / gist:1103906
Created July 25, 2011 10:58
Run a command programmtically in Symfony 2
<?php
$drop = $this->getApplication()->get("doctrine:database:drop");
$dropInput = new ArrayInput(array('--force' => '1'), $drop->getDefinition());
$drop->execute($dropInput, $output);
?>