Skip to content

Instantly share code, notes, and snippets.

View isaaclyman's full-sized avatar

Isaac Lyman isaaclyman

View GitHub Profile
@isaaclyman
isaaclyman / levDistArray
Created May 28, 2015 15:09
Damerau-Levenshtein: Compare a string to an array of strings, each of which may be one or more words which are compared separately; return X of the closest words/phrases
var levenshteinArray = function (item, itemArray, howMany) {
return itemArray.map(function (arrayItem) {
return {
item: arrayItem,
distance: splitLevDist(item, arrayItem)
};
}).sort(function (a, b) {
return a.distance - b.distance;
}).slice(0, howMany).map(function (item) {
return item.item;
@isaaclyman
isaaclyman / compile.js
Last active August 29, 2015 14:27
Using requireJS, jQuery and a unique template syntax, fill in text in an HTML document
'use strict';
// "source" should be the name of a text file (the '.txt' extension is assumed, so leave it off),
// formatted as follows:
/*
:css selector:
Text content for this element
::
@isaaclyman
isaaclyman / ProtractorHelper.cs
Last active April 12, 2016 16:54
ProtractorHelper: Run Protractor on multiple environments from a .NET Integration test
using System;
using System.ComponentModel;
using System.Diagnostics;
// Put this in whatever namespace you want, then construct and run it in an Integration test.
// The Run() method returns an exit code where 0 means the test was successful and anything else means it wasn't.
// So just assert that the result of Run() is 0, like so: `Assert.AreEqual(0, resultOfProtractorHelperDotRun);`
public class ProtractorHelper
{
private readonly string _configPath;
alias wow='git status'
alias such='git'
alias very='git'
alias wutido='git log -n 3'
alias loljk='git reset HEAD~'
alias aginagin='fc -s'
alias loool='git reset --hard HEAD'
alias wat='git diff'
@isaaclyman
isaaclyman / flattenArray.ts
Last active August 27, 2017 15:29
(TypeScript/ES6) Exports function flattenArray, which takes a nested array of numbers and flattens it into a non-nested array of numbers
export interface recursiveArray extends Array<number | Array<any>> { }
export function flattenArray(arrayToFlatten: recursiveArray = []): Array<number> {
let workingArray: Array<number> = []
for (const value of arrayToFlatten) {
if (Array.isArray(value)) {
workingArray = workingArray.concat(flattenArray(value))
} else {
workingArray.push(value)
@isaaclyman
isaaclyman / tsconfig.json
Last active August 31, 2017 18:36
My preferred TypeScript/TSLint settings
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"lib": ["es6", "dom"],
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"sourceMap": true,
@isaaclyman
isaaclyman / .stylelintrc
Last active September 3, 2017 15:25
My preferred StyleLint settings
{
"plugins": ["stylelint-order"],
"processors": ["stylelint-processor-html"],
"extends": "stylelint-config-standard",
"rules": {
"indentation": 2,
"no-empty-source": null,
"order/properties-alphabetical-order": true,
"selector-type-no-unknown": [true, {
"ignore": ["custom-elements"]
@isaaclyman
isaaclyman / protractor.config.js
Created August 31, 2017 18:43
A Protractor setup with some nice goodies (start maximized, watch console errors, take screenshots)
'use strict';
// Imagine there's a page helper that provides access to actual page elements in a unified place
var loginPage = require('./Helpers/Login.helper.js');
var fs = require('fs');
exports.config = {
specs: ['**/*.spec.js'],
capabilities: {
browserName: 'chrome',
@isaaclyman
isaaclyman / ResponsiveHelper.ts
Last active September 6, 2017 18:19
A reactive desktop/mobile threshold handler for consumption by computed properties in Vue.js
// We use the _.debounce method to prevent hundreds of unnecessary recalculations during click-and-drag resizing.
import * as _ from 'underscore'
import Vue, { ComponentOptions } from 'vue'
// This interface and the `as` statements at the end are the only TypeScript artifacts in this file. They can be removed
// for regular ES6 projects.
interface IResponsiveBus extends Vue {
handleResize: () => void
isMobile: boolean
}
@isaaclyman
isaaclyman / PromiseSingleton.ts
Created September 6, 2017 18:30
A pattern for promise result access in ES6, allowing decoupled access from multiple modules with a single shared promise. Good for GET APIs.
import { Api } from 'api'
class PromiseAccessSingleton {
public constructor () { this.init() }
private dataPromise: Promise<any>
private init (): void {
this.dataPromise = Api.GetData().then(data => {
// Transform `data` if needed...