Skip to content

Instantly share code, notes, and snippets.

View olegp's full-sized avatar

Oleg Podsechin olegp

View GitHub Profile
@olegp
olegp / analyzer.js
Created February 25, 2012 10:50
Time Combined Log Analyzer
var stream = require('fs-base').open(system.args[2]);
var stats = {}, paths = [], line;
while(line = stream.readLine()) {
try {
var l = line.substr(line.indexOf('"'));
l = l.split(/"([^"]+)"/);
var url = l[1].split(' ')[1].substr(1).split('/');
url = url.concat(url.pop().split('?'));
var time = +l[6].trim();
@olegp
olegp / gist:1652459
Created January 21, 2012 11:36
Disable logging in Ringo
var logLevels = {
"org.hibernate": "WARN",
"com.mchange": "ERROR",
"net.sf.ehcache": "ERROR"
};
var {Logger, Level} = org.apache.log4j;
for(var p in logLevels) {
Logger.getLogger(p).setLevel(Level[logLevels[p]]);
}
@olegp
olegp / workflow.md
Created January 1, 2012 20:05
Using GitHub issues and development workflow

When creating an issue, apply one of the following mutually exclusive labels:

  • Bug (ff0000 - red)
  • Feature (0000ff - blue)
  • Improvement (ffff00 - yellow)
  • Specification (7f7f7f - gray)
  • Urgent (007f00 - green)

Note, issues should map to quite big tasks of at least a few hours of work each. If there is a number of related smaller tasks that need to be done, please try to merge them into one issue.

@olegp
olegp / setup-node.sh
Created December 6, 2011 11:26
Bash script to install Node.js on Ubuntu from launchpad
# install node and node-dev (needed by node-fibers)
apt-get install python-software-properties curl -y
add-apt-repository ppa:chris-lea/node.js-devel <<EOF
EOF
apt-get update
apt-get install nodejs -y
apt-get install build-essential -y
apt-get install nodejs-dev -y
ln -s /usr/include/nodejs /usr/include/node
@olegp
olegp / cpu.sh
Created November 22, 2011 22:23
Cloudkick plugin for reporting CPU usage of processes based on their name
#!/bin/bash
# reports the combined cpu usage across all processes that include $1 in their name
N=0
LINES=$(ps -eo pcpu,args | grep $1)
while read -r LINE; do
C=$(echo $LINE | cut -d" " -f1)
N=$(echo "$N+$C" | bc)
done <<< "$LINES"
echo "status ok ok"
echo "metric cpu float $N"
@olegp
olegp / package.js
Created September 7, 2011 07:09
ringo-admin package
/**
* @fileoverview Script to package up an existing RingoJS application as a WAR.
*/
//require('core/string');
var {join, Path, makeDirectory, move, copy, exists, symbolicLink, base, removeTree} = require('fs');
var engine = require('ringo/engine');
var shell = require('ringo/shell');
var Parser = require('ringo/args').Parser;
@olegp
olegp / httpclient.js
Created May 30, 2011 17:22
CommonJS HttpClient implementation for Node using node-fibers
require('fibers');
var http = require('http');
exports.HttpClient = HttpClient;
// {method, url, headers, body}
// return value is {status:status, headers:{..}, body:[..]}
function HttpClient (settings) {
if (!(this instanceof HttpClient)) return new HttpClient(settings);
this.guts = {};
@olegp
olegp / gist:980315
Created May 19, 2011 06:56
Mustache tweak
// data
{
text: {
index: {
title: "Home"
}
},
posts: []
}
@olegp
olegp / inodes.sh
Created April 16, 2011 12:01
Cloudkick custom plugin for checking the number of inodes in use
#!/bin/bash
echo "status ok ok"
arr=$(df -i | grep xvda | tr "\t" "\n")
OLD_IFS="$IFS";
IFS=" ";
vars=( $arr );
IFS="$OLD_IFS"
echo "metric Inodes int" ${vars[1]}
echo "metric IUsed int" ${vars[2]}
echo "metric IFree int" ${vars[3]}
const GET = "GET", PUT = "PUT", POST = "POST", DELETE = "DELETE", HEAD = "HEAD";
function generate(base, endpoints) {
function camelCase(string) {
return string.charAt(0).toUpperCase() + string.substring(1);
}
function isArgument(component) {
return component.indexOf("{") == 0 &&
(component.indexOf("}") == component.length - 1);
}
var proxy = {};