Skip to content

Instantly share code, notes, and snippets.

View mhkeller's full-sized avatar

Michael Keller mhkeller

View GitHub Profile
/**
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

#393939 #747369 #515151 #a09f93 #2d2d2d #d3d0c8 #74736930 #cc99cc #f2777a #6699cc

// const monthLengths = {
// '2020-03': 31,
// '2020-02': 29,
// '2020-01': 31,
// '2019-12': 31,
// '2019-11': 30,
// '2019-10': 31,
// '2019-09': 30,
// '2019-08': 31,
@mhkeller
mhkeller / mv.sh
Created April 13, 2020 22:46 — forked from premek/mv.sh
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
function mv() {
if [ "$#" -ne 1 ]; then
command mv "$@"
return
@mhkeller
mhkeller / genDateRange.js
Created April 10, 2020 03:09
Generate a range of dates
// Adapted from here: https://stackoverflow.com/questions/4413590/javascript-get-array-of-dates-between-2-dates
module.exports = function genDateRange(start, end, format) {
let arr;
let dt;
for (arr = [], dt = new Date(start); dt <= end; dt.setDate(dt.getDate() + 1)) {
arr.push(new Date(dt));
}
if (format === 'strings') {
return arr.map(v => v.toISOString().slice(0, 10));
}
<script>
import { LayerCake, Svg, calcExtents, flatten } from 'layercake';
import { tweened } from 'svelte/motion';
import * as eases from 'svelte/easing';
import Line from '../../components/Line.svelte';
export let data;
export let shared;
const y = tweened(undefined, {
@mhkeller
mhkeller / count-string-occurrences.sql
Created October 15, 2019 19:31
count occurrences of a string across rows of a pgsql table
--useful for seeing if a css class exists across all instances of scraped pages in a pgsql database
--adapted from here https://stackoverflow.com/questions/36376410/counting-the-number-of-occurrences-of-a-substring-within-a-string-in-postgresql
select sum(array_length(string_to_array(html, 'SELECTOR'), 1) - 1) from TABLE_NAME
--should equal rows in the table
--or this to get occurrences per row
select (array_length(string_to_array(html, 'SELECTOR'), 1) - 1) as ct from TABLE_NAME ORDER BY ct DESC
@mhkeller
mhkeller / throttle.js
Created April 17, 2019 19:14
Throttle requests
const sleep = ms => new Promise(f => setTimeout(f, ms));
async function do_things() {
for (const thing of things) {
await Promise.all([
doThing(thing),
sleep(200)
});
}
}