Skip to content

Instantly share code, notes, and snippets.

View ccnokes's full-sized avatar

Cameron Nokes ccnokes

View GitHub Profile
@ccnokes
ccnokes / heic_to_jpeg.sh
Last active November 21, 2022 16:06
Bash script that converts .HEIC to .jpg files
#!/bin/bash
set -eu -o pipefail
count=$(find . -depth 1 -name "*.HEIC" | wc -l | sed 's/[[:space:]]*//')
echo "converting $count files .HEIC files to .jpg"
magick mogrify -monitor -format jpg *.HEIC
echo "Remove .HEIC files? [y/n]"
@getify
getify / 1.md
Last active October 15, 2020 01:44
BetterPromise: a strawman experiment in subclassing Promise and "fixing" a bunch of its awkward/bad parts

Some things that are "better" with this BetterPromise implementation:

  • BetterPromise # then(..) accepts a BetterPromise (or Promise) instance passed directly, instead of requiring a function to return it, so that the promise is linked into the chain.

    var p = BetterPromise.resolve(42);
    
    var q = Promise.resolve(10);
    
    p.then(console.log).then(q).then(console.log);
@sebmarkbage
sebmarkbage / Infrastructure.js
Last active March 14, 2024 17:40
SynchronousAsync.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
@cletusw
cletusw / angular-injection-to-import.js
Last active May 16, 2019 23:46
Converts the given angular injected parameter into an explicit require statement
/*
* Converts the given angular injected parameter into an explicit require statement
*
* Run this with jscodeshift
* @example
* jscodeshift . --specifier='Auth' --source='application/Auth'
*
* Live demo: https://astexplorer.net/#/gist/5492d2b9850a451d8e8d532bc64f21ce/latest
*
* Converts:
@rkbhochalya
rkbhochalya / optimize-images.sh
Created May 16, 2017 10:17
Recursively optimize PNG and JPEG images using convert command
# Recursively optimize PNG and JPEG images using convert command
#
# `convert` is part of ImageMagick (http://www.imagemagick.org/). You will need to install it first.
#
# Author: Rajendra Kumar Bhochalya (http://rkb.io)
#
# @see https://developers.google.com/speed/docs/insights/OptimizeImages
# Optimize all JPEG images in current directory and subdirectories
find . -name "*.jpg" -exec convert "{}" -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB "{}" \; -exec echo "{}" \;
@tpae
tpae / Trie.js
Created November 20, 2016 23:49
Trie.js - super simple JavaScript implementation
// Trie.js - super simple JS implementation
// https://en.wikipedia.org/wiki/Trie
// -----------------------------------------
// we start with the TrieNode
function TrieNode(key) {
// the "key" value will be the character in sequence
this.key = key;
@hallettj
hallettj / Makefile
Last active December 10, 2023 13:32
Makefile for transpiling with Babel & Flow in a Node app, or in a client- or server-side shared library
# Makefile for transpiling with Babel in a Node app, or in a client- or
# server-side shared library.
.PHONY: all clean
# Install `babel-cli` in a project to get the transpiler.
babel := node_modules/.bin/babel
# Identify modules to be transpiled by recursively searching the `src/`
# directory.
@anaisbetts
anaisbetts / stat-cache.js
Last active April 11, 2019 05:07
Make your Electron apps load faster, with this One Weird Trick
// Include this at the very top of both your main and window processes, so that
// it loads as soon as possible.
//
// Why does this work? The node.js module system calls fs.realpathSync a _lot_
// to load stuff, which in turn, has to call fs.lstatSync a _lot_. While you
// generally can't cache stat() results because they change behind your back
// (i.e. another program opens a file, then you stat it, the stats change),
// caching it for a very short period of time is :ok: :gem:. These effects are
// especially apparent on Windows, where stat() is far more expensive - stat()
// calls often take more time in the perf graph than actually evaluating the
const ToggleDisplayMatch = ({ component: Component, ...rest }) => (
<Match {...rest}>
{({ matched, ...props }) => (
<div style={{ display: matched ? 'block' : 'none' }}>
<Component {...props}/>
</div>
)}
</Match>
)
@rjz
rjz / ngrok_hostname.sh
Created August 9, 2016 16:20
Get ngrok hostname from command line
#!/bin/sh
# ngrok's web interface is HTML, but configuration is bootstrapped as a JSON
# string. We can hack out the forwarded hostname by extracting the next
# `*.ngrok.io` string from the JSON
#
# Brittle as all get out--YMMV. If you're still reading, usage is:
#
# $ ./ngrok_hostname.sh <proto> <addr>
#