Skip to content

Instantly share code, notes, and snippets.

@stockwellb
stockwellb / final.py
Last active December 5, 2017 02:30
Katya's final
#Katya Ruiz
#Final Project for COP 1000
#12/1/2017
#This is a program for calculating room sales for a stay
#at a Bed and Breakfast called Casa San Agustin in St. Augustine, FL.
#Global constants:
DISCOUNT_RATE = 0.10
SALES_TAX = 0.08
#Main function
@stockwellb
stockwellb / template.html
Created July 22, 2017 02:00
Template file for use with gist2html.js
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{title}}</title>
<meta name="description" content="{{description}}" />
</head>
<body>
<article id="main">
<time datetime="{{date}}" pubdate>{{date}}</time>
{{content}}
@stockwellb
stockwellb / gist2html.js
Created July 22, 2017 01:59
convert gist md to html
// credit https://kosamari.com/notes/Turn-Your-Gist-To-Html
var fs = require('fs');
var https = require('https');
var hljs = require('highlight.js') // https://highlightjs.org/
// Actual default values
var md = require('markdown-it')({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
<!DOCTYPE html>
<html lang="en">
<head>
<title>TheImmutableFabFour</title>
<meta name="description" content="The Immutable Fab Four: Strategies for immutable JavaScript" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
</head>
<body>
<article id="main">
<time datetime="2017-06-19" pubdate>2017-06-19</time>
@stockwellb
stockwellb / TypeScriptUnionTypes.md
Last active June 19, 2017 00:37
TypeScript Union Types: Using them in ionic, ngrx/store

TypeScript Union Types

Using them in ionic, ngrx/store

Here at [arraydigital] we’re using the ionic framework to create some of our mobile apps. I spent some time recently adding ngrx/store to one of our ionic projects and it gave me my first opportunity to see union types in the wild.

A union type is one of the advanced types in TypeScript. It describes a value that can be one of several types. So number | string is a type that can be either a number or a string. It is important to remember that a union type value will have only the members that are in common with the rest of the types in the union.

My first meeting with union types was using ngrx/store actions and reducers. Here are some simple actions from one of our ngrx/store applications. In the last line of the module: `export type Actions = LoadActio

@stockwellb
stockwellb / TheImmutableFabFour.md
Last active June 19, 2017 00:36
The Immutable Fab Four: Strategies for immutable JavaScript

The Immutable Fab Four

Strategies for immutable JavaScript

Immutable data is a concept that I had to deal with while writing my first reducer for ngrx/store. The idea behind immutable data is that it cannot be changed after creation. This simple shift in state management can make applications more simple to build and easier to debug. With a single source of truth you have a contract in hand that will free you of a whole class of problems that plague mutable applications. I’ll share what I’ve learned so far. Keep in mind that these examples stem from my experiences using ngrx/store but are in no way directly tied it.

Let’s start with some state: This state will consist of an object with an array of ids and an entities object that will store one key/value for each id in the ids array.

@stockwellb
stockwellb / fabFour.js
Last active May 28, 2017 21:24
Immutable Fab Four
let states = [];
const initialState = {
ids: [],
entities: {}
}
states = [...states, initialState]
@stockwellb
stockwellb / ma1-ngrx-reducer.js
Created May 21, 2017 14:15
ngrx code example for medium article
export function reducer(
state: State, action: Rate.Actions | Rates.Actions): State {
switch (action.type) {
case Rates.ActionTypes.LOAD: {
const rates = action.payload;
// return new state
}
case Rates.ActionTypes.LOAD_SUCCESS: {
const rates = action.payload;
// return new state
@stockwellb
stockwellb / ma1-ngrx-action.js
Last active May 21, 2017 14:15
ngrx code example for medium article
import { Action } from ‘@ngrx/store’;
import { Rate } from ‘../models/models’;
import { type } from '../util';
export const ActionTypes = {
LOAD: type(‘LOAD’),
LOAD_SUCCESS: type(‘LOAD_SUCCESS’)
}
export class SetAction implements Action {
readonly type = ActionTypes.LOAD;
}
const _ = require('lodash');
const request = require('request');
(function () {
const phrase = "may the force be with you";
const key = "TZlKw4gd1qFQhA2CbMLa";
const url = "http://thesaurus.altervista.org/service.php?language=en_US&output=json&key=" + key + "&word=";
const getSynonyms = (word) => {
return new Promise((resolve, reject) => {