Skip to content

Instantly share code, notes, and snippets.

Avatar

Bennett McElwee bennettmcelwee

View GitHub Profile
View google-link-cleaner.user.js
View num2.js
var digitToNum = digit => ({v:digit, f:`${digit}`})
var partitions = x => times(i => [take(i+1, x), drop(i+1, x)], x.length - 1)
const negop = {o:(a) => ({o:negop, a, v:-a.v, f:`-${a.f}`})}
const unops = [negop]
const addop = {o:curry((a,b) => ({o:addop, a, b, v:a.v+b.v, f:`${a.f}+${b.f}`}))}
const subop = {o:curry((a,b) => ({o:subop, a, b, v:a.v-b.v, f:`${a.f}-${b.f}`}))}
const mulop = {o:curry((a,b) => ({o:mulop, a, b, v:a.v*b.v, f:`${a.f}x${b.f}`}))}
const divop = {o:curry((a,b) => (b.v != 0 ? {o:divop, a, b, v:a.v/b.v, f:`${a.f}/${b.f}`} : null))}
const biops = [addop, subop, mulop, divop]
View trello-format.js
$(() => {
const observer = new MutationObserver(addFormatControls)
observer.observe(document.querySelector('body'), {attributes: true, subtree: true})
function getCommentInput (optionsElement) {
return $(optionsElement).closest('.comment-box').find('textarea').get(0)
}
function wrapSelection (input, wrap) {
const selection = input.value.slice(input.selectionStart, input.selectionEnd)
@bennettmcelwee
bennettmcelwee / freegal-tweaks.js
Last active Jan 23, 2018
Snippet to inject into Freegal pages to make them more readable
View freegal-tweaks.js
// Change New Releases page to a complete text listing with hover images
if (window.location.pathname === '/homes/new_releases') {
$('<style>\
.videos-shadow-container { display: none; }\
.my-top-100-page { height: auto; }\
.album-shadow-container > .album-scrollable { display: none; }\
.album-shadow-container > button { display: none; }\
.album-shadow-container + h3 { display: none; }\
.hnr-at { border-spacing: 3px; border-collapse: separate; margin-left: -3px; font-family: "Helvetica Neue", sans-serif; }\
.hnr-at .album-link img {position: absolute; }\
View Freegal hover listing
$(`<style>
.fp-album-wrapper:not(:hover) .fp-track-listing {
display: none;
margin-left: -0.5em;
}
.album-title .fp-track-listing {
position: absolute;
z-index: 1;
}
.fp-track-listing {
@bennettmcelwee
bennettmcelwee / stringify.js
Created Dec 6, 2017
Version of JSON.stringify limitied to a specific depth.
View stringify.js
// Similar to JSON.stringify but limited to a specified depth (default 1)
const stringify = (obj, depth) => {
if (depth === undefined) {
depth = 1 // default
}
return ( ! obj) ?
JSON.stringify(obj) :
(typeof obj === 'object') ?
'{' + (depth < 1 ? '?' : (
Object.keys(obj).map((k) => k + ': ' + stringify(obj[k], depth - 1)).join(', ')
View .bashrc
if [ -f ~/bin/sensible.bash ]; then
source ~/bin/sensible.bash
fi
if [ -f ~/bin/git-completion.bash ]; then
source ~/bin/git-completion.bash
fi
export EDITOR="open -t -n -W"
@bennettmcelwee
bennettmcelwee / search.html
Last active Feb 11, 2016
Show a search menu
View search.html
<title>Search</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
.hide { display: none; }
.search, #term, #go {
display: block;
font: 20px/50px sans-serif;
width: 100%;
View allmusic-search.html
<title>Search</title>
<script>
const name = 'AllMusic.com';
const baseUrl = 'http://www.allmusic.com/';
const searchRel = 'search/all/';
var s = window.prompt('Search ' + name, '');
window.location.href = s ? baseUrl + searchRel + s : baseUrl;
</script>
@bennettmcelwee
bennettmcelwee / bookmarkleteer.html
Last active Dec 19, 2015
Web page that can turn Javascript into a bookmarklet
View bookmarkleteer.html
<!DOCTYPE html>
<html>
<head>
<title>Bookmarkleteer</title>
<script>
/**
* Bookmarklet Compiler
*
* Inspired by Moxley Stratton - http://www.moxleystratton.com/
*/