Skip to content

Instantly share code, notes, and snippets.

View ashhitch's full-sized avatar
💭
Slinging Divs

Ash Hitchcock ashhitch

💭
Slinging Divs
View GitHub Profile
@ashhitch
ashhitch / auth-guard.ts
Created August 9, 2016 13:11 — forked from sonicoder86/auth-guard.ts
Upgrading to the new Angular 2 router - part 11
// auth-guard.ts
import { Injectable } from '@angular/core';
import {
CanActivate,
Router,
ActivatedRouteSnapshot,
RouterStateSnapshot
} from '@angular/router';
import { AuthService } from './services/auth/auth.service';
@ashhitch
ashhitch / web-servers.md
Created June 30, 2016 15:26 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@ashhitch
ashhitch / es2015-iterator-with-generator.js
Last active February 9, 2016 09:46
ES2015 Object iterator
let user = {
name: "sam", totalReplies: 17, isBlocked: false
};
user[Symbol.iterator] = function * (){
let properties = Object.keys(this);
let count = 0;
let isDone = false;
@ashhitch
ashhitch / subclass.js
Created January 22, 2016 14:06
Class and Sub Class ES2015
class Advertisement {
constructor(title, link){
this.title = title;
this.link = link;
}
_buildContent(){
return `<h1>${this.title}</h1>
<a href="${this.link}">${this._linkText()}</a>`;
@ashhitch
ashhitch / es2015-class.js
Created January 22, 2016 13:59
ES2015 basic class example
class TagManager {
constructor(topicId) {
this.topicId = topicId;
}
addTag(tagName) {
API.createTag(tagName, this.topicId);
}
removeTag(tagName) {
@ashhitch
ashhitch / Iterating-Map.js
Created January 22, 2016 09:22
Iterating Maps With for...of using destructuring ES2015
let recentPosts = new Map();
recentPosts.set( "Sam", "ES2015" );
recentPosts.set( "Tyler", "CoffeeScript" );
recentPosts.set( "Brook", "TypeScript" );
for( let [user, postTitle] of recentPosts ){
console.log(`${user} = ${postTitle}`);
}
@ashhitch
ashhitch / JavaScript-Composition.js
Created January 21, 2016 11:45
JavaScript Composition Example
const barker = (state) => ({
bark: () => console.log('Woof, I am ' + state.name)
})
const driver = (state) => ({
drive: () => state.position = state.position + state.speed
})
const murderRobotDog = (name) => {
let state = {
name,
@ashhitch
ashhitch / efficient-loop.js
Created January 19, 2016 14:19
efficient Javascript loop
for (var i = 0, len = a.length; i < len; i++) {
// Do something with a[i]
}
@ashhitch
ashhitch / conditional-expressions.js
Created January 19, 2016 14:13
JavaScript ternary operator for conditional expressions
var allowed = (age > 18) ? "yes" : "no";
@ashhitch
ashhitch / boolean-jQuery-Toggle.js
Created November 5, 2015 15:04
Boolean jQuery Toggle
$('itemwanttochange').toggleClass(function(){
return booleanVal ? "IS_TRUE" : "IS_FALSE";
});