Skip to content

Instantly share code, notes, and snippets.

@mgmarlow
mgmarlow / load-modal.css
Last active October 8, 2015 16:45
Ajax loading modal
.load-modal {
display: none;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: rgba(255, 255, 255, .8)
url("img/ajax-loader.gif")
@mgmarlow
mgmarlow / shuffle.fsx
Created January 7, 2016 18:56
Shuffle List Algorithm
let shuffle (arr : _[]) =
let rnd = new System.Random()
let swap a b (arr : _[]) =
let temp = arr.[a]
arr.[a] <- arr.[b]
arr.[b] <- temp
for i in 0..arr.Length-1 do
swap i (rnd.Next(arr.Length)) arr
arr
@mgmarlow
mgmarlow / todo.py
Created April 22, 2016 18:44
Todo API with Flask
#!flask/bin/python
from flask import Flask, jsonify, abort, make_response, request
app = Flask(__name__)
tasks = [
{
'id': 1,
'title': u'Buy groceries',
'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
@mgmarlow
mgmarlow / main.md
Last active March 10, 2017 16:38
Intro to JavaScript Lecture Notes

Introduction to JavaScript

Agenda

  • History
  • Fundamentals
  • Types
  • Flow Control
  • Functions and Objects
  • Modern JS
@mgmarlow
mgmarlow / normalizeScroll.js
Last active March 16, 2017 21:41
Normalize scroll wheel for consistent cross-browser results
// Reasonable defaults
var PIXEL_STEP = 10;
var LINE_HEIGHT = 40;
var PAGE_HEIGHT = 800;
function normalizeWheel(/*object*/ event) /*object*/ {
var sX = 0, sY = 0, // spinX, spinY
pX = 0, pY = 0; // pixelX, pixelY
// Legacy
@mgmarlow
mgmarlow / store.ts
Created March 30, 2017 15:41
Angular 2 Data Store
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs/Rx';
@Injectable()
export class EmployeeStore {
private _selectedEmployees: BehaviorSubject<any[]> = new BehaviorSubject([]);
public selectedEmployees: Observable<any[]> = this._selectedEmployees.asObservable();
addOrRemoveEmployee (employee) {
let existingEmployee = this._selectedEmployees.getValue()
@mgmarlow
mgmarlow / build-angular2-lib.ps1
Last active April 27, 2017 21:56
Building Angular 2 Component Libraries with Powershell
if (Test-Path dist) {
Remove-Item dist -Recurse -Force
}
if (Test-Path build) {
Remove-Item build -Recurse -Force
}
$NGC = "node_modules/.bin/ngc.cmd"
$ROLLUP = "node_modules/.bin/rollup.cmd"
@mgmarlow
mgmarlow / app.state.ts
Last active August 19, 2017 21:53
Adaptable Angular Data Store
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class AppState {
private _isRed = new BehaviorSubject<boolean>(false);
isRed: Observable<boolean> = this._isRed.asObservable();
toggleRed() {
import { Component, Input, HostBinding } from '@angular/core';
import { AppState } from './app.state';
@Component({
selector: 'hello',
template: `
<h1>Hello Data Store!</h1>
<button (click)="toggleRed()">Toggle Red</button>
`
})
@mgmarlow
mgmarlow / websocket.service.ts
Created August 29, 2017 15:59
Angular Websocket Service
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subscriber } from 'rxjs/Subscriber';
@Injectable()
export class WebsocketService {
private ws: WebSocket;
createObservableSocket(url: string, openSubscriber: Subscriber<any>): Observable<any> {
this.ws = new WebSocket(url);