Skip to content

Instantly share code, notes, and snippets.

@hamiltondanielb
hamiltondanielb / routes.js
Created July 14, 2016 16:35
React Authorization
import React from 'react';
import { Route, IndexRoute } from 'react-router';
import { requireAuth } from './utils/auth';
import App from './components/App';
import Login from './containers/LoginPage';
import TeamPage from './containers/TeamPage'; // eslint-disable-line import/no-named-as-default
import NotFoundPage from './components/NotFoundPage.js';
export default (
@hamiltondanielb
hamiltondanielb / calc
Created August 26, 2016 20:21
Calculator
function Calculator() {
}
Calculator.prototype.calc = function(str) {
var signs = ["*", "+","/"]; // signs in the order in which they should be evaluated
var funcs = [multiply, add, divide]; // the functions associated with the signs
var tokens = str.split(" "); // split the string into "tokens" (numbers or signs)
console.log(tokens)
for (var round = 0; round < signs.length; round++) { // do this for every sign
for (var place = 0; place < tokens.length; place++) { // do this for every token
@hamiltondanielb
hamiltondanielb / guidgen.js
Created October 3, 2016 20:35
Guid Generator
function s4(){
return Math.floor((1+ Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
module.exports ={
guidWithDash: function() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
@hamiltondanielb
hamiltondanielb / gist:63f2644b199d63f00725abb37b54c7a5
Last active August 30, 2017 20:11
Javascript IsUnique String
function isUnique( s ) {
var chars = {}
var dup = true;
for (var i = 0; i < s.length; ++i) {
if ((s[i] in chars)) {
return false;
}
chars[s[i]] = 1;
}