Skip to content

Instantly share code, notes, and snippets.

View alloyking's full-sized avatar
🎧
.

Tim Shultis alloyking

🎧
.
View GitHub Profile
@alloyking
alloyking / bench.js
Created September 8, 2013 02:34
API Bench
var benchrest = require('bench-rest'); //---- https://github.com/jeffbski/bench-rest
var flow = 'YOUR-HTTP-URL'; // simple get request
var runOptions = {
limit: 50, // concurrent connections
iterations: 1 // number of iterations to perform
};
benchrest(flow, runOptions)
.on('error', function (err, ctxName) { console.error('Failed in %s with err: ', ctxName, err); })
.on('end', function (stats, errorCount) {
@alloyking
alloyking / open.js
Created September 9, 2013 03:00
node api request
var http = require('http');
var req = http.request('http://api.ews.cdew.net/XYHHM1VJKGZ63/data?key=tempkey&feed=continuous', function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
#!/bin/sh
#
# chkconfig: 35 99 99
# description: Node.js /home/nodejs/sample/app.js
#
. /etc/rc.d/init.d/functions
USER="nodejs"
/**
* The functional pattern, defined in Douglas Crockford's "Javascript: The Good Parts", allows for
* JavaScript to achieve both inheritance and information hiding (private variables) with a compact syntax.
* The specification that is passed in, as well as potentially more vars you may define in each pseudo-class, are not
* accessible from the object that is returned, we consider these private variables. Public vars may
* be added to the "that" return object as desired.
*/
/**
* Person is our base pseudo-class
// all objects inherit from Object.prototype,
// we can add capabilities like so:
console.log('adding capabilities to Object.prototype');
if (typeof Object.prototype.totalBills != 'function') {
Object.prototype.totalBills = function () {
if (this.bills && this.bills.constructor === Array) {
var total = 0;
for (var i=0; i<this.bills.length; i++) {
/**
* Constructor Invocation Pattern
* Requires use of the "new" keyword, allows for inheritance, but no information hiding
* The Functional Pattern is recommended over the Constructor Invocation Pattern
*/
// create a constructor function for the base class
var Person = function (spec) {
// pseudo-class vars
spec.name = spec.name || '';
@alloyking
alloyking / UrlRequest.h
Created December 28, 2013 14:20
ios post request (likely crappy)
//
// UrlRequest.h
// form
//
// Created by timshultis on 12/26/13.
// Copyright (c) 2013 timshultis. All rights reserved.
//
#import <Foundation/Foundation.h>
@alloyking
alloyking / repo_clone.js
Last active January 4, 2016 13:39
Nodejs clone
//requires:
//npm install nodegit
//npm install fs-extra
var git = require('nodegit'),
fs = require('fs-extra'),
path = './webfiles',
repo = 'https://alloyking@bitbucket.org/alloyking/bracket-app-auto-update.git';
@alloyking
alloyking / result_params.js
Last active August 29, 2015 13:56
js urlParams
param = {
params: [],
set: function(key, value){
if(!this.update(key, value)){
this.add(key, value);
}
},
add: function(key, value) {
param_obj = {};
param_obj[key] = value;
@alloyking
alloyking / nwmnode.sh
Created February 26, 2014 14:22
centos startup nodejs
#!/bin/sh
#
# chkconfig: 35 99 99
# description: Node.js /home/nodejs/sample/app.js
#
. /etc/rc.d/init.d/functions
# Creamos un fichero PID para monit
SCRIPT="$(basename $0)"