Skip to content

Instantly share code, notes, and snippets.

View justsml's full-sized avatar
🔥
#BLM

Dan Levy justsml

🔥
#BLM
View GitHub Profile
@justsml
justsml / INSTALL.md
Last active August 8, 2023 17:31
Add Page Up and Page Down Keyboard Bindings to Sublime Text 3 (and 2)

Add PageUp PageDown (Keyboard Shortcut Scrolling) to Sublime Text 3 (and 2)

  • Save ScrollLinesFixedCommand.py to ~/Library/Application Support/Sublime Text 3/Packages/User/ folder
  • Copy the suggested usage from sublime-keymap.json into your ~/Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-keymap

Hey Sublime, why the hell this isn't an available keybinding by default? Seriously, I'm tired of looking up how to do this every so often. For most of my work I've switched to Visual Studio Code, the Open Source IDE from Microsoft (still sounds wierd)... But it's genuinely amazing.

@justsml
justsml / insertAdjacentHTML.js
Last active February 26, 2021 10:24 — forked from eligrey/insertAdjacentHTML.js
insertAdjacentHTML polyfill
/*
* Updated w/ insertAdjacentElement
* @author Dan Levy @justsml
* 2016-06-23
*
* Credit: @lyleunderwood - afterend patch/fix
*
* ```js
* import { insertAdjacentElement } from './libs/insertAdjacentHTML.js';
* Use either:
// Promise-as-memoized func
let p = Promise((resolve, reject) => setTimeout(() => resolve(5), 10))
p.then(console.log) // === 5
// Reuse result to hearts content, now cached locally in `p`
p.then(console.log) // === 5

// =======
// You can't change a value for a promise instance, it is point-in-time.
@justsml
justsml / README.md
Created July 14, 2016 21:42 — forked from joshdover/README.md
Idiomatic React Testing Patterns

Idiomatic React Testing Patterns

Testing React components seems simple at first. Then you need to test something that isn't a pure interaction and things seem to break down. These 4 patterns should help you write readable, flexible tests for the type of component you are testing.

Setup

I recommend doing all setup in the most functional way possible. If you can avoid it, don't set variables in a beforeEach. This will help ensure tests are isolated and make things a bit easier to reason about. I use a pattern that gives great defaults for each test example but allows every example to override props when needed:

@justsml
justsml / calculate-nested-item-offset.markdown
Created September 4, 2016 19:59
Calculate Nested Item Offset

Calculate Nested Item Offset

Calculate item scroll offset inside multiple nested vertical scroll regions.

A Pen by Daniel Levy on CodePen.

License.

// transformy is an object mapping tool to
// transform objects to another object defaults
function transformy({ mutate = {}, input = {}, schema = {}, omit = [], loose = true }) {
return Object.keys(input).map((key) => {
const mutated = {};
const tkey = mutate.hasOwnProperty(key) ? mutate[key] : null;
if (omit.indexOf(key) !== -1) return mutated;
if (typeof input[key] !== 'undefined' && schema.hasOwnProperty(tkey)) {
mutated[tkey] = input[key];
} else if (typeof schema[key] !== 'undefined') {
@justsml
justsml / KeyValueTools.js
Last active October 2, 2016 22:59
Key Value Parser & Stringify Example: QueryString- & Hash-Style String Parsing & Encoding Using `Functional Programming` in JavaScript!
/**
* Key Value Helpers
* Features QueryString & Hash Helper Utils
* API for `QS` & `Hash` inspired by the `JSON` browser API.
*
* Implements `parse` & `stringify`
*
* JSON.stringify({ foo: 'bar' })
* -> '{"foo":"bar"}'
* QS.stringify({ foo: 'bar' })
@justsml
justsml / composable-javascript.md
Created September 22, 2016 00:05
Example Compose Functions - Example 'Partial Application'
const compose = function _compose() {
  return (input) => {
    return Array.from(arguments)
      .reduce((last, fn) => fn(last), input);
  }
}
const composeRight = function _compose() {
  return (input) => {
 return Array.from(arguments)
/**
@example
arr = [{position: 100}, {position: 50}, {position: 99}, {position: 1}]
SortaHelping.sort(arr, SortaHelping.position)
*/
function SortaHelping() {
return {
sort, // SortaHelping.sort(arr, SortaHelping.position) prevents re-application of sort automatically
@justsml
justsml / keybindings.json
Created October 10, 2016 21:21
Visual Studio Code - Config Files
[
{ "key": "cmd+alt+down", "command": "editor.action.moveLinesDownAction",
"when": "editorTextFocus && !editorReadonly" },
{ "key": "cmd+alt+up", "command": "editor.action.moveLinesUpAction",
"when": "editorTextFocus && !editorReadonly" },
{ "key": "alt+down", "command": "cursorPageDown",
"when": "editorTextFocus" },
{ "key": "alt+shift+down", "command": "cursorPageDownSelect",
"when": "editorTextFocus" },
{ "key": "alt+up", "command": "cursorPageUp",