Skip to content

Instantly share code, notes, and snippets.

View brendanashworth's full-sized avatar
🐦
bunting

Brendan Ashworth brendanashworth

🐦
bunting
View GitHub Profile
@brendanashworth
brendanashworth / main.sh
Created August 12, 2014 22:38
Install php 5.5 on Ubuntu 12.04
#!/bin/bash
# Credits to http://askubuntu.com/a/343567
sudo apt-get install python-software-properties -y
sudo add-apt-repository ppa:ondrej/php5 -y
sudo apt-get update -y
sudo apt-get install php5 -y
echo ""
@brendanashworth
brendanashworth / debug.h
Created October 12, 2014 20:35
C debug macro
/* From https://github.com/brendanashworth/wookie
* src/util.h
* licensed under MIT license
*/
/**
* A debug macro that prints out file, line number, then message.
* @param msg The debug message to print.
*/
#define DEBUG(msg) printf("[DEBUG] %s:%d; %s\n", __FILE__, __LINE__, msg)
var util = require('util');
var events = require('events');
// Create the object constructor
function Cat(name) {
this.name = name;
}
// Inherit the EventEmitter
util.inherits(Cat, events.EventEmitter);
Cat.prototype.meow = function(message) {
this.emit('meow', message);
}
// Create a cat
var kitty = new Cat('Mittens');
kitty.on('meow', function(msg) {
console.log('We got a message from Mittens:', msg);
});
kitten.on('meow', function(msg) {
console.log(msg);
});
kitten.emit('meow', msg);
var foo = 10; // any value works
foo.__proto__.test = function() {
console.log("Success");
};
foo.test();
// This is the constructor
function Client(name, age) {
this.name = name;
this.age = age;
}
Client.prototype.contact = function() {
console.log("Now contacting " + this.name + "...");
}
Client.prototype.zipcode = 12345;
// Utilizes a closure
Client.prototype.defaultAge = (function() {
return prompt("What should the default age be?");
})();
function Person(age) {
if (age > 18) this.age = age;
}
Person.prototype.age = 18;