Skip to content

Instantly share code, notes, and snippets.

@peterjacobson
peterjacobson / gra.js
Last active December 8, 2022 20:29
A simple number guessing game in node.js
//var process = require('process');
var readline = require('readline');
var randomNumber = Math.round(Math.random() * 10);
var lives = 5;
var terminal = readline.createInterface(
{
input : process.stdin,
output : process.stdout
@peterjacobson
peterjacobson / treeObjectExample.js
Last active September 21, 2015 02:43
Basic OOJS tree example
// Write your Orange Tree code here - you may use constructor functions
var Tree = function(color) {
// this.age = age
this.color = color
}
Tree.prototype = {
age: 0,
grow: function() {
@peterjacobson
peterjacobson / CreateInvoiceXeroAPI.js
Last active August 29, 2015 14:28
creating an Xero invoice with the xero npm package - Status code:500, TypeError: Not a buffer at Sign.sign (crypto.js:429:27)
var express = require('express');
var router = express.Router();
var Xero = require('xero');
var xero = new Xero(process.env.CONSUMER_KEY, process.env.CONSUMER_SECRET);
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', {
description: 'Luke and pete to make this awesome app'
function intro(){
// watch your indentation here. rule #1, perfectly indent your code, ALWAYS!
// else will lead to bugs and much confusion over nothing
var hi = document.getElementById('introduction');
hi.style.display = 'initial';
var img = document.getElementById('pic');
img.style.display = 'none';
}
@peterjacobson
peterjacobson / enumerables_in_ruby.rb
Last active August 29, 2015 14:25
iterating through collections
def mode(num_list)
new_array = []
freq = num_list.inject(Hash.new(0)) { |h,v| h[v] += 1; h}
# can you tell me what 'h' or 'v' means? I just got it from stackoverflow maybe you can chane it to a value that is easy to understand
#-----------PETE: ----------------
#easiest way to check what's going on is to print everything you don't understand:
@peterjacobson
peterjacobson / coding_articulation.rb
Last active August 29, 2015 14:24
Coding vocabulary, articulation, reasoning & communication
# HOW TO
# articulate, reason, communicate and think about code
# key vocabulary is in '', e.g. 'highest level'
# I find the articulation and vocabulary around coding really important.
# You'll slowly pick it up from videos, stack overflow and tutorials.
# Perhaps it is worth a little focus in its own right...
# I welcome feedback: is this guide helpful or confounding?
@peterjacobson
peterjacobson / creature.js
Created May 14, 2015 10:07
OO prototypes & helper abstraction
function B() {
this.name = 'flim';
this.shell = '<div id="' + this.name + '""></div>';
this.id = '#' + this.name;
this.lastCoords = this.getCoords();
};
B.prototype.start = function() { //
setInterval(this.move.bind(this), 100)
// setInterval(this.poop.bind(this), 150)