Skip to content

Instantly share code, notes, and snippets.

@dwighthouse
dwighthouse / parsePath.js
Last active January 5, 2021 18:22
Second attempt at high quality SVG Path Parser. Should handle all valid and invalid SVG paths with a single pass, without modifying any of the original data.
const CommandData = {
M: {
name: 'MoveTo',
chunk: 2,
},
L: {
name: 'LineTo',
chunk: 2,
},
H: {
diff -y --suppress-common-lines <(xxd PATH1) <(xxd PATH2)
@dwighthouse
dwighthouse / DisableTypingAnimationDiscord.js
Last active March 16, 2020 17:41
Disable Typing Animation in Discord by running this in the console
// For some reason, the typing notification (and its associated animation) seems to use a lot of processing
// This causes the fans on my laptop to run audibly whenever someone is typing
// This script brute force disables it, since there's no option to reduce animation in Discord
// To run, apply the following code to the console. You can access the console within the devtools, accessible with hotkey:
// Mac: Command+Option+I
// Windows: Control+Shift+I
// Running this script only affects your current Discord session, so it will have to be done every time you start Discord
// Once you finish pasting this, close the devtools with the X in the top corner
document.head.appendChild(document.createElement('style')).innerHTML = '[class^="typing-"] { display: none !important; }';
@dwighthouse
dwighthouse / YouTubeScreenshot.js
Last active February 12, 2020 20:45
Download YouTube Screenshot by running this in the console
(() => {
const youtubeVideoSelector = 'video';
const video = document.querySelector(youtubeVideoSelector);
const width = video.videoWidth;
const height = video.videoHeight;
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.width = width;
@dwighthouse
dwighthouse / ThisLikeRef.js
Created September 11, 2019 20:31
Using This-Like Ref Structure to Solve Hook State Updating and Function Reference Problems
import React, { memo, useCallback } from 'react';
import ChildComponent from './wherever/ChildComponent.js';
const updateChild = (props, childId, changes) => {
props.onUpdate({
type: 'childChanged',
childId: childId,
changes: changes,
});
};

App.js

'use strict';

const React = require('react');

const Store = require('./Store');
const Thing = require('./Thing');
@dwighthouse
dwighthouse / InsertBetween.js
Last active November 16, 2015 21:03
InsertBetween.js - Inserts stuff between other stuff in React context
'use strict';
var React = require('react');
// Inserts stuff between other stuff in React context
// Usage
// <InsertBetween separator={', '}>
// <span>1</span>
// <span>2</span>
@dwighthouse
dwighthouse / jssSheet2.js
Last active August 29, 2015 14:25
New attempt to add helper function to react-jss.
'use strict';
var _ = require('lodash');
// JSS styling
var jss = require('jss').create();
// Order matters!
// https://github.com/jsstyles/jss-camel-case/issues/1
jss.use(require('jss-extend'));
@dwighthouse
dwighthouse / jssSheet.js
Created July 25, 2015 01:59
Old JSS React Wrapper
'use strict';
var _ = require('lodash');
// JSS styling
var jss = require('jss');
// Order matters!
// https://github.com/jsstyles/jss-camel-case/issues/1
jss.use(require('jss-extend'));
@dwighthouse
dwighthouse / Lo-Dash Recipes
Last active February 24, 2016 16:58
Ways to accomplish various tasks in Lo-Dash, focusing on terse-ness
// Lo-Dash 3.8.0
// -----------------------------------------------------------------------------
// Search String to Object
// -----------------------------------------------------------------------------
// Handles many slightly malformed styles (see tests)
// Expects each query to be separated by '&'
// Expects each pair to be separated by '='
_.chain(queryString) // or get the current query string: window.location.search