Skip to content

Instantly share code, notes, and snippets.

View AloofBuddha's full-sized avatar

Benjamin Cohen AloofBuddha

View GitHub Profile
@AloofBuddha
AloofBuddha / gist:d95ad453031b860c484b
Created November 13, 2014 08:54
Linked List search in Python
# we want to match data, not a Node, as search
# shouldn't require any Node creation either
def search(self, data):
node = self.head
while node:
if node.data == data:
return node
else:
node = node.nextNode
@AloofBuddha
AloofBuddha / db-server.js
Last active August 29, 2015 14:25
node.js database server
var http = require('http');
url = require('url');
var database = {}; // will need to read from file here
var setRegex = /^\/set\?.+=.+$/, // /set?somekey=somevalue
getRegex = /^\/get\?key=.+$/; // /get?key=somekey
http.createServer(requestListener).listen(4000);
// ES6 of the week: arrow functions and lexical scope
// https://github.com/lukehoban/es6features
// arrow functions are a shorthand for function syntax,
// which make them a lot more succint for functions that take functions
// (i.e. 'higher order functions')
var evens = [2,4,6,8,10];
const initialState = {
activeIndex: null,
flights: []
}
export default function reducer (state = initialState, action){
switch(action.type) {
// lets create first.
// This means we create a flight then add it to a *copy* of the list.
case CREATE_NEW_FLIGHT:
@AloofBuddha
AloofBuddha / README.md
Last active February 3, 2017 17:18
Event Delegation Examples

Event Delegation

Here's an example of event delegation and when you would use it.

Here is an interactive jsbin of with-delegation.js https://jsbin.com/pufide/8/edit?html,js,console,output JSBin is in general a great resource for trying out front-end code without having to do a lot of setup!


All files share the same index.html

Front-End JS Concepts

Front-end JS is different than Node for a number of reasons that can be confusing. Hopefully the info here will help you clear up some of the confusion you may have!

Important Note Upfront All of the concepts described here still apply in the modern day, but recent tools and trends have made some less relevant than others. All of this information still applies when sending over a plain HTML file, but a specific dev tool called Webpack solves a number of these problems and has as a result become a pretty essential tool for front-end development. I will try to make a note when it applies!

Including your css/js files

When we send back an HTML file as the response to a GET request, we can include any number of other resources using their URLs. This means using `

@AloofBuddha
AloofBuddha / walkthrough.md
Last active April 17, 2017 16:48
Bones Setup Walkthrough

My own walkthrough of setting up Bones

Replace kaizerroll with your own username wherever you see it in the following examples!

Also, only one person on the team needs to create the Github repo (1-2). Everyone else can be added as a project member and clone it.

  1. Fork bones from https://github.com/FullstackAcademy/bones
  • click the fork button at the top-right
  • You should now have your own remote copy of this repo listed with your own Github repositories
  • Mine is at https://github.com/kaizerroll/bones
@AloofBuddha
AloofBuddha / recursion-review.md
Last active April 26, 2018 01:47
Recursion Review for C4Q

Recursion and Dynamic Programming

Recursion

Recursion is fundamentally the idea of defining a function in terms of itself. This sounds trippy and unnecessary, so let's look at a canonical example. The 'hello world' of a recursive functions is

function fibbonacci(n) { ... }

The fibonnaci sequence is the sequence of numbers

@AloofBuddha
AloofBuddha / closure-tutorial.md
Last active September 18, 2018 18:55
Closure tutorial

Global Scope, Inner Scope and Closures

This tutorial aims to cover the topics of

  • Global Scope
  • Inner Scope (or sometimes called Function Scope)
  • and Closures

in the JavaScript language.


@AloofBuddha
AloofBuddha / sequelize-belongs-to-example.js
Created September 29, 2016 15:15
An explanation of how to define a One-to-One relationship in Sequelize and different ways of create the linked objects
// Product Model definition, called 'product' and associated with table 'products'
var Product = this.sequelize.define('product', {
title: Sequelize.STRING
});
// User Model definition, called 'user' and associated with table 'users'
var User = this.sequelize.define('user', {
first_name: Sequelize.STRING,
last_name: Sequelize.STRING
});