Skip to content

Instantly share code, notes, and snippets.

View omarkj's full-sized avatar

Omar Yasin omarkj

  • Vancouver, BC, Canada
View GitHub Profile
@omarkj
omarkj / EventBus.js
Created October 31, 2010 17:44
Simple EventBus in JS
"use strict";
var EventBus = function() {
var events = [];
var p_on = function(eventName, callback) {
if (!events.some(function(e) {
return e.name == eventName; })) {
var new_event = {
name: eventName,
cb: callback
};
var sys = require('sys'),
spawn = require('child_process').spawn,
openssl = spawn('python', ['test.py']);
openssl.stdout.on('data', function (data) {+
sys.print('signature is valid: ' + data);
});
openssl.stderr.on('data', function (data) {
sys.print('Error: ' + data);
var fs = require('fs'),
assert = require('assert'),
crypto = require('crypto');
var msg = "Gaur!";
fs.readFile('PrivateKey.pem', 'utf-8', function(e,pri) {
var signer = crypto.createSign('sha256').update(msg);
var signature = signer.sign(pri, output_format='base64');
fs.readFile('PublicKey.pem', 'utf-8', function(e,pub) {
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@omarkj
omarkj / gist:517141
Created August 10, 2010 11:55
Using EventEmitters
var amqp = require('./amqp'),
sys = require('sys'),
net = require('net'),
events = require('events');
var RabbitClient = function() {
events.EventEmitter.call(this);
var self = this;
var connection = amqp.createConnection({ host: cfg.AMQP.Host });
connection.addListener('ready', function () {
// Based on http://www.diveintojavascript.com/projects/sprintf-for-javascript
String.prototype.format = function() {
var i = 0, a, f = this, o = [], m, p, c, x, s = '';
while (f) {
if (m = /^[^\x25]+/.exec(f)) {
o.push(m[0]);
}
else if (m = /^\x25{2}/.exec(f)) {
o.push('%');