Skip to content

Instantly share code, notes, and snippets.

View qzaidi's full-sized avatar
💭
smiling

Qasim Zaidi qzaidi

💭
smiling
View GitHub Profile
@qzaidi
qzaidi / gist:1289509
Created October 15, 2011 12:42
node-magento-api
var xmlrpc = require('xmlrpc'),
sys = require('sys');
var config = {
host: 'www.mymagentohost.com',
port: 80,
path: '/api/xmlrpc/',
login: 'apilogin',
pass: 'myapikey'
@qzaidi
qzaidi / nginx-multibackend.conf
Created March 11, 2012 01:35
nginx a/b test config
upstream rrbackend {
server 127.0.0.1:8080 weight=3;
server 127.0.0.1:8888;
}
map $cookie_backend $backend {
default rrbackend;
experimental 127.0.0.1:8888;
}
@qzaidi
qzaidi / loadspeed.js
Created June 26, 2012 03:12
Phantomjs page load measurements
var page = require('webpage').create(),
system = require('system'),
address,time,tries,j;
if (system.args.length === 1) {
console.log('Usage: loadspeed.js <some URL>');
phantom.exit();
} else {
address = system.args[1];
tries = Number(system.args[2]) || 10;
@qzaidi
qzaidi / jsstack.js
Created August 4, 2012 04:21
jsstack - pstack like tool for node.js apps
#!/usr/bin/env node
"use strict";
var debug = require('_debugger');
var c = new debug.Client();
function main() {
console.log('requesting trace');
c.reqBacktrace(function(err,trace) {
if (!err) {
@qzaidi
qzaidi / pbewithmd5anddes.js
Last active June 1, 2020 22:09
Emulates Java's insecure PBEWITHMD5ANDDES with node.js crypto. Useful for interop with old java programs.
"use strict";
/*
* Emulates Java's PBEWITHMD5ANDDES for node.js
*/
var crypto = require('crypto');
var pbewithmd5anddes = {
KDF: function(password,salt,iterations) {
@qzaidi
qzaidi / gist:5835999
Created June 22, 2013 05:40
dashing job for fetching CPU usage and Instance count from AWS. Create an aws-config.json, and update your AutoScalingGroupName here. It assumes a List widget named servers and a Meter widget named cpu in your dashboard. { "accessKeyId": "XXXXXX", "secretAccessKey": "XXXXX", "region": "ap-southeast-1" }
"use strict";
var AWS = require('aws-sdk');
AWS.config.loadFromPath(__dirname + '/../aws-config.json');
var autoscaling = new AWS.AutoScaling();
var cloudwatch = new AWS.CloudWatch();
function goFigure() {
var e = new Date();
@qzaidi
qzaidi / info_schema.sql
Last active August 29, 2015 13:56
mysql information schema queries
# Show largest tables and indexes
SELECT CONCAT(table_schema, '.', table_name),CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,ROUND(index_length / data_length, 2) idxfrac FROM information_schema.TABLES ORDER BY data_length + index_length DESC LIMIT 10;
# Show temp table stats
show global status like '%tmp%'
@qzaidi
qzaidi / perf_schema.sql
Last active August 29, 2015 13:56
mysql performance schema
# verify if its on/off
SHOW VARIABLES LIKE 'perf%';
# List frequently running queries
select * from events_statements_summary_by_digest order by count_star desc limit 4;
# List queries creating temp tables
select * from events_statements_current where CREATED_TMP_DISK_TABLES > 0 limit 1\G;
@qzaidi
qzaidi / nginx.conf
Created February 20, 2014 10:49
stacked nginx
recursive_error_pages on;
location / {
try_files $uri @nodesrv;
}
location @nodesrv {
proxy_pass http://localhost:5000;
proxy_intercept_errors on;
error_page 404 = @phpsrv;
}
@qzaidi
qzaidi / cluster
Created March 22, 2014 18:09
script wrapper for running node daemons
#!/usr/bin/env node
//# vi: ft=javascript
"use strict";
var util = require('util');
var recluster = require('recluster');
var path = require('path');
var fs = require('fs');
var args = require('optimist').argv;