Skip to content

Instantly share code, notes, and snippets.

View mattlubner's full-sized avatar

Matt Lubner mattlubner

View GitHub Profile
@mattlubner
mattlubner / base62.js
Last active October 14, 2020 20:46 — forked from kevinyan815/base62.js
BigInt-compatible Base62 Conversion Functions
// requires ES2020 for BigInt support
const digits = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
function toBase62(number) {
if (number === 0n) {
return '0';
}
let result = '';
let remaining = number;
@mattlubner
mattlubner / TruncateTextAtBreak.jsx
Created May 29, 2020 01:55
Truncate a line of text where it breaks naturally, so table column widths don't explode.
import React from 'react';
import styled from 'styled-components';
const Relative = styled.div`
position: relative;
`;
const TextWidth = styled.div`
opacity: 0;
text-overflow: clip;
@mattlubner
mattlubner / razzle-plugin-node-runtime-vars.js
Created January 28, 2020 19:29
Razzle plugin to force certain environment variables to be resolved dynamically at runtime for the nodejs bundle
import _ from 'lodash';
/**
* The passed list of environment variables will be removed from the nodejs
* instance of webpack.DefinePlugin, so they can be resolved dynamically at
* runtime.
* @example
* // Include this in the plugins array exported by razzle.config.js
* const nodeRuntimeVarsPlugin = createRazzlePluginNodeRuntimeVars('PORT', 'HOST');
* @param {String} ...nodeRuntimeVars
@mattlubner
mattlubner / nvm_link_abs.sh
Last active October 7, 2016 23:13
Bash function to npm link packages using symbolic links w/ absolute paths
@mattlubner
mattlubner / itunes_filter_new_media.sh
Last active October 7, 2016 23:18
Useful shell script that takes a file list as stdin and returns only those files not loaded into the active iTunes library
#!/bin/bash
permitted_file_extensions="mov|mp4|m4v|mpg|mpeg|m2v|mp2|ite|aac|m4a|m4b|m4p|mp3|caf|aiff|aif|aifc|au|sd2|wav|snd|amr|3ga"
eval "active_library="$(defaults read com.apple.iApps iTunesRecentDatabases)
printf -v active_library '%b' "${active_library[0]//%/\\x}"
active_library="${active_library#file://localhost}"
if [[ ! -e "$active_library" ]]; then
exit 1
fi