Skip to content

Instantly share code, notes, and snippets.

Paul "Joey" Clark joeytwiddle

Block or report user

Report or block joeytwiddle

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@joeytwiddle
joeytwiddle / nn-images.html
Last active Nov 17, 2019
A neural network to generate images
View nn-images.html
<html>
<body>
<canvas id="canvas" width="512" height="512"></canvas>
<!-- <script src="./nn-image.js"></script> -->
<script>
class Network {
layers = []
weightsLayers = []
@joeytwiddle
joeytwiddle / github_get_all_forks.sh
Last active Nov 7, 2019
Add all forks of the current repo as remotes
View github_get_all_forks.sh
#!/usr/bin/env bash
set -e
# See also: https://github.com/frost-nzcr4/find_forks (same thing but in python)
origin_url="$(git remote show origin | grep 'Fetch URL:' | sed 's+.*: ++')"
full_repo_name="$(echo "$origin_url" | sed 's+.*github.com/++')"
forks_url="https://api.github.com/repos/${full_repo_name}/forks"
View make-before-await.js
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const fn = (ms) => delay(ms).then(() => console.log('done after ' + ms));
// Sequential
async function test1() {
const [one, two] = [await fn(2000), await fn(1000)];
console.log('mikael1 finished');
}
View Asking Good Questions.md

Asking Good Questions

Suggestions to help you ask good questions on StackOverflow, GitHub issues and IRC, as well as when asking colleagues face-to-face.

General rule: Put at least as much effort into the question as you would like others to put into the answer.

Preparation

  1. Check that you have the latest version of the software. (The bug might have already been fixed.)
View VSCode versus WebStorm - what I like and don't like.md

Preamble

I have used WebStorm at work for the past three years. But last month I used VSCode exclusively for four weeks, because I wanted to learn it. I noted my observations here.

Eventually, as a deadline approached, I switched back to WebStorm. Why? VSCode is very good, and I was impressed. But I still find WebStorm is slightly better at a few things which I use very frequently. These small improvements really add up when I'm trying to get stuff done.

In keeping with the Pareto principle, small advantages with only a few commonly used features are enough to make one editor stand out for me. Specifically, "Go to Definition/References", "Searching" and "Carrying imports" are so important, that just making these more convenient means that all other concerns are irrelevant.

So, for the reader's convenience, these are the first few features I will address below.

View get_url_scheme_for_ios_app.sh
#!/usr/bin/env bash
set -e
cache_dir="$HOME/Library/Group Containers/K36BKF7T3D.group.com.apple.configurator/Library/Caches/Assets/TemporaryItems/MobileApps"
if command -v find >/dev/null && command -v mktemp >/dev/null && command -v unzip >/dev/null && command -v grep >/dev/null
then :
else
echo "This script requires the follow executables to run: find mktemp unzip grep"
@joeytwiddle
joeytwiddle / asyncWrappersForRestify.js
Last active Oct 7, 2019
Helper to use promises in restify (might also work for express)
View asyncWrappersForRestify.js
/**
* Use restify with promises
*
* Restify middleware and route handlers are passed a callback function `next`
* which must be called on success, or on an error.
*
* But you may prefer to define your middleware and routes using promises or
* async functions instead of using callbacks.
*
* To achieve that, simply wrap your middleware functions in `middleware()` and
View cooldown-monitor.js
"use strict";
/*
Simulates an object which can heat up and overheat, but with a constant rate of cooling over time.
Useful for throttling when you want to provide an initial allowance.
For example, it could be used to manage the overheating of a weapon in a game, or to avoid errors from generating huge logfiles, but without throttling the first few errors.
@joeytwiddle
joeytwiddle / move_dropbox_to_ext4_fs.sh
Created Nov 6, 2018
Creates a file with an ext4 filesystem inside it, and moves Dropbox into that filesystem
View move_dropbox_to_ext4_fs.sh
#!/bin/bash
set -e
set -x
# You could put the fs file and the mountpoint inside your home folder
#new_fs_file="$HOME/dropbox_partition.ext4fs"
#mountpoint="$HOME/Dropbox.mnt"
# But that may not work if you are using a fuse-mounted homefolder (e.g. encrypted with encfs)
new_fs_file="/home/dropbox_for_$USER.ext4fs"
mountpoint="/mnt/dropbox.$USER"
@joeytwiddle
joeytwiddle / optional.js
Last active Nov 12, 2019
Getting properties from an object which might be null
View optional.js
// A common situation in Javascript:
//
// We have a variable `obj`, and we want to get `obj.foo.bar`
//
// But `obj` might be null or undefined, or `obj.foo` might be null or undefined
//
// So how can we try to get `obj.foo.bar` without risking an error?
// Here are a few different ways to do that. Which one is clearest?
You can’t perform that action at this time.