Skip to content

Instantly share code, notes, and snippets.

View nickytonline's full-sized avatar
🚀

Nick Taylor nickytonline

🚀
View GitHub Profile
interface Association<TKey, TValue> {
key: TKey;
info: TValue;
}
interface StringKeyInfo {
keyIndexes: Array<Association<string, number>>;
keyIsSet: Array<Association<string, boolean>>;
}
@nickytonline
nickytonline / preview-head.html
Created July 11, 2018 13:48
Grid Points Background for Storybook
<style>
body {
background-image: linear-gradient(transparent 0px, transparent 1px, rgb(255, 255, 255) 1px, rgb(255, 255, 255) 20px), linear-gradient(to right, rgb(54, 69, 79) 0px, rgb(54, 69, 79) 1px, rgb(255, 255, 255) 1px, rgb(255, 255, 255) 20px);
background-position: 1.1875rem;
background-size: 1.25rem 1.25rem;
background-attachment: fixed;
}
</style>
@nickytonline
nickytonline / async-await-promise-all.js
Last active August 12, 2018 07:43
async/await with Promise.all
// In response to https://twitter.com/housecor/status/930108010558640128
function doubleAfter2Seconds(x) {
return new Promise(resolve => {
resolve(x * 2);
}, 2000);
}
async function addAsync(x) {
const { a, b, c } = await Promise.all([
doubleAfter2Seconds(10),
@nickytonline
nickytonline / snippets.js
Created September 16, 2018 23:32
Chrome Extension Snippets
function getActiveTab() {
return new Promise((resolve, reject) => {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const activeTab = tabs.find(t => t.active);
resolve(activeTab);
});
});
}
@nickytonline
nickytonline / object-entries-polyfills.js
Last active July 15, 2019 00:45
Having fun recreating some lodash functionality and polyfills
// Just having fun creating some polyfills.
/**
* A polyfill for Object.prototype.entries.
*
* @returns {[string, any][]} An array of tuples where each tuple is a key/value pair.
*/
Object.prototype.entries = Object.prototype.entries || function() {
const obj = this;
@nickytonline
nickytonline / mini-expect.js
Last active July 20, 2019 04:13
Recreated a portion of the expect library
function expect(actual) {
function prettyJSON(objectToSerialize) {
return JSON.stringify(objectToSerialize, null, '\t')
}
return {
toBe(expected) {
if (actual === expected) {
console.log('✅ Pass')
} else {
@nickytonline
nickytonline / webpack.config.js
Last active December 2, 2019 04:34
@babel/preset-env not transpiling to ES5
module.exports = {
entry: {
acme_co_es5: [
"@babel/polyfill",
"./public/javascripts/webpack_entry_points/acme_co.js"
]
},
resolve: {
extensions: [".js", ".jsx"]
},
@nickytonline
nickytonline / useDragAndDrop.js
Last active August 31, 2020 21:44
A (P)React hook for attaching drag and drop events to an element.
/**
* Hook for drag attaching drag and drop functionality to a DOM element
*
* @param {object} props
* @param {Function} props.onDragOver The handler that runs when the dragover event is fired.
* @param {Function} props.onDragExit The handler that runs when the dragexit/dragleave events are fired.
* @param {Function} props.onDrop The handler that runs when the drop event is fired.
*/
export function useDragAndDrop({ onDragOver, onDragExit, onDrop }) {
const [element, setElement] = useState(null);
@nickytonline
nickytonline / cobalt2_agnoster_theme.jpg
Last active November 7, 2020 09:29
My VS Code Setup
cobalt2_agnoster_theme.jpg
@nickytonline
nickytonline / front-end-resources.md
Last active November 12, 2020 20:25
Some Front-End Resources