Skip to content

Instantly share code, notes, and snippets.

Avatar

Alan Johnson AmaxJ

  • NYC
View GitHub Profile
@AmaxJ
AmaxJ / blackjack.scala
Last active December 10, 2017 16:03
blackjack
View blackjack.scala
object BlackJack {
def main(args: Array[String]) = {
val deck = new Deck()
val players = addPlayers(3)
println(deck.deal)
println(deck.cards)
}
def addPlayers(num: Int) = {
@AmaxJ
AmaxJ / practice.js
Created January 1, 2017 22:22
practice with dan
View practice.js
//Installed node modules: jquery underscore request express jade shelljs passport http sys lodash async mocha chai sinon sinon-chai moment connect validator restify ejs ws co when helmet wrench brain mustache should backbone forever debug
var _ = require('underscore');
var num = "the number: ";
var num2 = "10";
// console.log(num + num2)
var num3 = 42; //string //integer
View tommy.js
function vacancies(arr) {
var vacancies = [];
for (var i=0; i < arr.length; i++) {
if (arr[i] === "vacancy") {
vacancies.push(arr[i]);
}
}
if (vacancies.length === 0) {
return "no vacancies";
}
View react-lifecycle-parent-child.jsx
import React from "react";
import { render } from "react-dom";
const ParentComponent = React.createClass({
getDefaultProps: function() {
console.log("ParentComponent - getDefaultProps");
},
getInitialState: function() {
console.log("ParentComponent - getInitialState");
return { text: "" };
View gist:bfb604d9901be9fc844b

Javascript

Javascript: The Good Parts -- Beginner/Intermediate

http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742

Legendary book, a must-read for any Javascript programmer at least once. Goes into the basics of Javascript with the assumption that the reader is an experienced programmer already, coming from another language or already understands a fair bit about Javascript itself. Very good review of basics and more advanced concepts (like scope/closure, functions as first class objects, etc).

Javascript Design Patterns (Stoyan Stefanov) -- Intermediate

View Creating FB Graph Objects
//Create a new Graph Object
FB.api(
'me/objects/video.movie',
'post', {
'object': {
'title': 'Sample Movie',
'type': 'video.movie',
'image': 'http://stuffpoint.com/cats/image/41633-cats-cute-cat.jpg',
'url': 'http://localhost:9000',
'description': 'Example Description Here',
@AmaxJ
AmaxJ / resource.py
Created June 14, 2015 23:08
user resource
View resource.py
from app import db
from app.models import User
from flask_restful import Resource, fields, marshal, reqparse
user_field = {
'id' : fields.Integer,
'username' : fields.String,
'email' : fields.String
}
View gist:1f2554d81092d0b5c25b
(function(){
var inherits = function(subClass, superClass){
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
}
var inherits2 = function (ChildClass, ParentClass) {
function Surrogate () {}
Surrogate.prototype = ParentClass.prototype;
ChildClass.prototype = new Surrogate();
View gist:18f2a3a3949f66752097
// write nLengthSubstrings(string, n)
var nLengthSubstrings = Assessment.nLengthSubstrings = function(str, num){
var result = [];
if(str.length < num) { return result; }
else {
for(var i=0; i+num <= str.length; i++){
var x = i + num;
var sub= str.substring(i, x);
result.push(sub);
}