Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@samartioli
samartioli / simple_load_balancers.cfg
Created December 3, 2017 15:55
Simple configs for haproxy and ngingx load balancing
### HAPROXY EXAMPLE ###
global
maxconn 4096
defaults
log global
mode http
option httplog
option dontlognull
option forwardfor
function test() {
return new Promise(function(resolveA, rejectA) {
// return rejectA('rejectA');
return resolveA('resolveA');
})
.then(function(results) {
return new Promise(function(resolveB, rejectB) {
return rejectB('rejectB');
@samartioli
samartioli / eslintrc.js
Created December 28, 2015 21:39
ESLint config example
var MAX_CHARS = 120;
var SPACES_PER_TAB = 4;
var MAX_NESTED_CALLBACKS = 3;
var MAX_PARAMS = 3;
var MAX_STATEMENTS = 10;
module.exports = {
// http://eslint.org/docs/rules/
root@b8bad52e873c:/app# npm install --save opencv
npm info it worked if it ends with ok
npm info using npm@3.3.6
npm info using node@v5.0.0
npm info attempt registry request try #1 at 12:48:42 AM
npm http request GET https://registry.npmjs.org/opencv
npm http 200 https://registry.npmjs.org/opencv
npm info retry fetch attempt 1 at 12:48:43 AM
npm info attempt registry request try #1 at 12:48:43 AM
npm http fetch GET https://registry.npmjs.org/opencv/-/opencv-3.2.0.tgz
@samartioli
samartioli / gist:325bdc864d9f157b631f
Created November 28, 2014 21:09
Setting up Centos 6.5 with node
sudo su # become root
# yum -y install http://mirror.pnl.gov/epel/6/i386/epel-release-6-8.noarch.rpm
yum -y install http://mirror.pnl.gov/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y update
# #exclude=kernel necessary in order to build npm package. 
# If you skip this step 'yum install npm' will fail
sed -i 's/exclude=kernel/#exclude=kernel/' /etc/yum.conf
yum -y install git nodejs npm redis multitail
useradd -p $(perl -e'print crypt("node", "salty")') node
useradd -G node -p $(perl -e'print crypt("newuser", "salty")') newuser
@samartioli
samartioli / gist:5979763
Created July 11, 2013 22:19
In hiphop-php, can I save the state of objects in memory?
With hiphop-php, is it possible to save state across requests without using serialize and unserialize. In other words, put something in memory from one request, and pull it in during another request?
An example of where this would be beneficial, would be in the Bootstrap process in ZEND.
To be able to bootstrap the applciaiton one time before routing, and then save that state, using it over and over again for each subsequent request.
@samartioli
samartioli / Folder Structure
Created July 1, 2013 18:11
fopen does not take include_path into consideration as of HipHop VM v2.1.0-dev. fopen's 3rd param when set to true should take all include paths into consideration when trying to open the file. http://php.net/manual/en/function.fopen.php
A basic folder structure to replicate this is as follows:
./fopen.php
./someIncludeFolder/
./someIncludeFolder/someIncludedFile.php
@samartioli
samartioli / loadConfig.php
Created June 24, 2013 11:02
hhvm [HipHop VM v2.1.0-dev (rel)] syntax error, unexpected $end, expecting TC_DOLLAR_CURLY or TC_QUOTED_STRING when executing parse_ini_file. Issue occurs when an ini value ends with a dollar sign: somekey = "value$" but does not error if the dollar sign is in the middle of the string: anotherkey = "value$value"
<?php
$filename = 'test.ini';
$iniArray = parse_ini_file($filename, true);
var_dump($iniArray);
@samartioli
samartioli / Python Memoization question
Last active December 16, 2015 14:58
From the example at: http://ujihisa.blogspot.com/2010/11/memoized-recursive-fibonacci-in-python.html How do I access the cache of fibonacci numbers after running the function?
def memoize(f):
cache = {}
def decorated_function(*args):
if args in cache:
return cache[args]
else:
cache[args] = f(*args)
return cache[args]
return decorated_function
@samartioli
samartioli / gist:5314410
Last active December 15, 2015 19:49
Answer in python to problem: "in how many ways can you represent n cents using 25 cents, 10 cents, 5 cents and 1 cent coins"
def append_return(n,L):
M=L[:]
M.append(n)
return M
def cents(n,L=[]):
global t
if n == 0:
#print L
t+=1