Skip to content

Instantly share code, notes, and snippets.

var binarySearch = Assessment.binarySearch = function(array, target){
var point = Math.floor(array.length / 2);
if( array[point] === target)
return target;
else if ( target > array[array.length -1] || target < array[0])
return -1;
else if( array[point] > target )
return binarySearch(array.splice(0, point - 1), target);
else if( array[point] < target )
return binarySearch(array.splice(point + 1, array.length - 1), target);
// 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);
}
(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();
@AmaxJ
AmaxJ / resource.py
Created June 14, 2015 23:08
user resource
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
}
//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',

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

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: "" };
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";
}
@AmaxJ
AmaxJ / practice.js
Created January 1, 2017 22:22
practice with dan
//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