Skip to content

Instantly share code, notes, and snippets.

@jsejcksn
jsejcksn / clipboard.deno.test.ts
Last active Jun 28, 2020
Deno text clipboard
View clipboard.deno.test.ts
import {assert, assertEquals} from './deps.ts';
import {readText, writeText} from './mod.ts';
type Test = [string, () => void | Promise<void>];
const tests: Test[] = [
[
'reads/writes without throwing', async () => {
const input = 'hello world';
await writeText(input);
@jsejcksn
jsejcksn / _clone-all-gists.deno.ts
Created Jun 9, 2020
Clone all gists using Deno
View _clone-all-gists.deno.ts
// Deno v1.0.5
// deno run --allow-net --allow-run --allow-write --unstable _clone-all-gists.deno.ts --user your_username --token your_github_access_token [--directory parent_directory_to_clone_into]
// https://developer.github.com/v3/gists/
import * as path from 'https://deno.land/std@0.56.0/path/mod.ts';
import {parse} from 'https://deno.land/std@0.56.0/flags/mod.ts';
import {writeJson} from 'https://deno.land/std@0.56.0/fs/mod.ts';
type GistMetadata = {
created_at: string;
@jsejcksn
jsejcksn / like-yt-video.user.js
Created May 1, 2020
Smash that like button (add current YouTube video to liked videos)
View like-yt-video.user.js
(() => {
const likeVideo = () => {
const [likeButton] = [...document.querySelectorAll('button')]
.filter(node => (
typeof node.getAttribute('aria-label') === 'string'
&& node.getAttribute('aria-label').startsWith('like this video')
));
let likeAnchor = likeButton;
@jsejcksn
jsejcksn / figma-make-components.user.js
Created Feb 29, 2020
Create multiple components from top level layers in Figma
View figma-make-components.user.js
(numberOfComponentsToMake => {
const wait = ms => new Promise(res => setTimeout(res, ms));
const target = document.querySelector('canvas');
const makeComponentFromSelectedLayer = () => target.dispatchEvent(new KeyboardEvent(
'keydown',
{
altKey: true,
keyCode: 75,
@jsejcksn
jsejcksn / log-inspect.js
Created Jan 8, 2020
Use inspect to log deep objects in Node.js
View log-inspect.js
import util from 'util';
const log = (() => {
const log = (...values) => {
console.log(...values.map(value => util.inspect(value, {
colors: true,
depth: null,
getters: true,
showHidden: false,
...log.options,
@jsejcksn
jsejcksn / monty-hall.js
Last active Jul 27, 2019
Monty Hall problem: Simulation
View monty-hall.js
#!/usr/bin/env node
'use strict';
function makeADeal (changeDoor, initialDoorNumber) {
if (initialDoorNumber && (initialDoorNumber < 1 || initialDoorNumber > 3))
throw new Error('If provided, the inital door number must be 1, 2, or 3.');
function randomInt (max = 1, min = 0) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@jsejcksn
jsejcksn / nodejs-uninstall-deletion-list.txt
Created May 21, 2019
Uninstalling system Node.js and npm in preparation for reinstall via nvm
View nodejs-uninstall-deletion-list.txt
# This list was derived from the macOS installer for Node.js v10.15 and might not be complete
# Additionally, if you have modified your npm prefix, you will also need to address that directory
/usr/local/bin/node
/usr/local/include/node
/usr/local/lib/dtrace/node.d
/usr/local/lib/node_modules
/usr/local/share/doc/node
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
@jsejcksn
jsejcksn / 1p-parser.js
Last active May 14, 2019
1Password 1pif data parser Node.js module
View 1p-parser.js
#!/usr/bin/env node
// cli usage: `node 1p-parser.js input.1pif`
'use strict';
const getJSON = require('1pif-to-json');
(async () => {
const items = await getJSON(process.argv.slice(2)[0]);
@jsejcksn
jsejcksn / generate-element.js
Last active Jan 30, 2019
A function for creating an element with its content and attributes
View generate-element.js
'use strict';
function genEl (tagName, attributes, ...childNodes) {
const el = document.createElement(tagName);
if (attributes) {
for (const [prop, value] of Object.entries(attributes)) {
if (prop === 'style' && (Array.isArray(value) || value instanceof Map)) {
for (const declaration of value) {
el.style.setProperty(...declaration);
}
@jsejcksn
jsejcksn / autoresize-textarea.js
Last active Jan 19, 2019
Auto-resize textarea
View autoresize-textarea.js
for (const tx of document.getElementsByTagName('textarea')) {
tx.style.setProperty('height', `${tx.scrollHeight}px`);
tx.style.setProperty('overflow-y', 'hidden');
tx.addEventListener('input', (ev) => {
ev.target.style.setProperty('height', 'auto');
ev.target.style.setProperty('height', `${ev.target.scrollHeight}px`);
});
}