Skip to content

Instantly share code, notes, and snippets.

class Queue {
constructor() {
this.items = {};
this.headIndex = 0;
this.tailIndex = 0;
}
enqueue(item) {
this.items[this.tailIndex] = item;
this.tailIndex++;
@NicholasMurray
NicholasMurray / AngularJS Geolocation Directive
Created February 18, 2015 23:25
AngularJS Geolocation Directive
angular
.module('directives', [])
.directive('geolocation', function($window) {
return {
restrict: "E",
template: '<div></div>',
link: function (scope, element, attrs) {
if ($window.navigator && $window.navigator.geolocation) {
$window.navigator.geolocation.getCurrentPosition(function(position) {
element.html('<div>Your geolocation is latitude:<span id="latitude"></span> and longitude:<span id="longitude"></span></div>');
.error {
color: red;
}
<form [formGroup]="form">
<div *ngFor="let prop of personProps">
<label>{{ prop.label }}:</label>
<div [ngSwitch]="prop.type">
<input *ngSwitchCase="'text'" [type]="prop.type" [formControlName]="prop.key">
<input *ngSwitchCase="'number'" [type]="prop.type" [formControlName]="prop.key">
<div *ngSwitchCase="'radio'">
<label *ngFor="let option of prop.options">
<input type="radio"
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule, FormsModule} from "@angular/forms";
import { FirstReactiveFormComponent } from './first-reactive-form.component';
describe('FirstReactiveFormComponent', () => {
let component: FirstReactiveFormComponent;
let fixture: ComponentFixture<FirstReactiveFormComponent>;
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'app-first-reactive-form',
templateUrl: './first-reactive-form.component.html',
styleUrls: ['./first-reactive-form.component.css']
})
export class FirstReactiveFormComponent implements OnInit {
form: FormGroup;
@NicholasMurray
NicholasMurray / AngularJS Geolocation Directive Jasmine Geolocation Not Available Test
Created February 18, 2015 23:27
AngularJS Geolocation Directive Jasmine Geolocation Not Available Test
describe('Directive tests: geolocation ', function() {
var $window, navigator;
describe('when called on a browser that does not have geolocation available ', function() {
beforeEach(module('geolocationApp'));
beforeEach(inject(function($rootScope, $compile, _$window_) {
element = angular.element('<geolocation class="geolocation"><p>This is a geolocation app</p></geolocation>');
@NicholasMurray
NicholasMurray / launch.sh
Created April 14, 2017 11:13 — forked from ltfschoen/launch.sh
Shell script that generates separate Terminal tabs to run a Ruby on Rails web server then automatically opens associated webpage in your web browser
#!/bin/bash
# File: ~/launch.sh
# Original Code Reference: http://dan.doezema.com/2013/04/programmatically-create-title-tabs-within-the-mac-os-x-terminal-app/
# New-BSD License by Original Author Daniel Doezema http://dan.doezema.com/licenses/new-bsd/
# Modified by Luke Schoen in 2017 to include loading new tabs for Rails Server and automatically open webpage in browser.
# References: https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html
import os
from PIL import Image, ImageOps, ImageDraw
def draw_ellipse(image, bounds, width=1, outline='grey', antialias=4):
# Use a single channel image (mode='L') as mask.
# The size of the mask can be increased relative to the imput image
# to get smoother looking results.
mask = Image.new(
size=[int(dim * antialias) for dim in image.size],
mode='L', color='black')