Skip to content

Instantly share code, notes, and snippets.

@jon49
jon49 / MPA-Auto-Scroll-Auto-Focus.js
Last active June 8, 2023 23:41
MPA progressive enhancement for scrolling back to position and focusing on previously focused element.
function getCleanUrlPath() {
let url = new URL(document.location.href)
return url.pathname.replace(/\/$/, "")
}
window.addEventListener('beforeunload', () => {
let active = document.activeElement
localStorage.pageLocation = JSON.stringify({
href: getCleanUrlPath(),
y: window.scrollY,
@jon49
jon49 / index.js
Created January 30, 2018 09:02
Last youtube videos on the survival podcast
var fs = require('fs'),
cheerio = require('cheerio'),
fetch = require('node-fetch')
// https://gist.github.com/endel/321925f6cafa25bbfbde
const Pad = size => number => {
let s = String(number)
while (s.length < (size || 2)) { s = "0" + s }
return s
}
@jon49
jon49 / GetEarliestFSharpFileModifiedDate.fsx
Last active December 3, 2017 21:23
See the earliest F# file you have written
open System.IO
let sourceDir = [ __SOURCE_DIRECTORY__ ]
let getFiles searchPattern dir =
seq {
yield! Directory.EnumerateFiles(dir, searchPattern)
}
let log x =
@jon49
jon49 / validation.fsx
Last active November 5, 2022 16:35
Using lists in validation in F#
open Microsoft.FSharp.Quotations.Patterns
open System
open Microsoft.FSharp.Reflection
open Microsoft.FSharp.Quotations
module P = Microsoft.FSharp.Quotations.Patterns
// http://www.fssnip.net/h1
let rec eval = function
| Value(v,t) -> v
| Coerce(e,t) -> eval e
@jon49
jon49 / scripts.yml
Created April 12, 2016 16:19
YAML Script Example File
# scripts run with npm. to build to package.json
# in command line in directory `.../mobiledlr/dist`
# `node ./tasks/buildPackage`
scripts:
# bring together api.yml file with d.ts definitions
# print to public
api: |
cpx "../ts/api/**" api
&& node ./tasks/api-generator.js
@jon49
jon49 / addScriptsToPackage.ts
Created November 23, 2015 18:43
Use yaml for npm command line scripts and merge with package.json
import r = require('ramda')
import yaml = require('js-yaml')
import {readFile, writeFile} from 'fs'
var package = require('../package.json')
readFile('../scripts.yml', 'utf-8', (err, file) => {
if (err) {
console.log('Error reading scripts.yml', err)
return process.exit(1)
@jon49
jon49 / object-transform-example.ts
Last active September 23, 2015 17:48
object transform
const objectTransform = r.curry(function OT_(template, obj) {
let originalObject = obj
function OT(template, obj) {
let o = obj
const
t = template,
keys = r.keys(template)
const
result = r.reduce((acc, key: string) => {
const mapT = t[key], val = <any> r.path([key], o)