Instantly share code, notes, and snippets.

Coding Hard

Jonathan Goode u01jmg3

View GitHub Profile
View unique-identifiers.php
* Fancy ID generator that creates 20-character string identifiers with the following properties:
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
View fix-dictionaries.bat
@echo off
set regPath="HKEY_CURRENT_USER\Software\Microsoft\Spelling\Dictionaries"
set regName="_Global_"
set truncate=true
if "%truncate%"=="true" (
reg ADD %regPath% /t REG_MULTI_SZ /v %regName% /d "C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Office\16.0\be70806f\Proofing\RoamingCustom.dic" /f
) else (
for /f "tokens=2*" %%a in ('REG QUERY %regPath% /v %regName%') do set "regData=%%~b"
View create-app-logo-sizes.bat
@echo off
echo Creating 59 icons, please wait.
im-convert ../../src/assets/images/app-logo-no-gradient.png ^
( -clone 0 -resize 2208x1242 -background #1f3165 -gravity center -extent 2208x1242 -write ../../platforms/ios/Assess/Images.xcassets/LaunchImage.launchimage/Default-Landscape-736h.png ) ^
( -clone 0 -resize 2048x1536 -background #1f3165 -gravity center -extent 2048x1536 -write ../../platforms/ios/Assess/Images.xcassets/LaunchImage.launchimage/Default-Landscape@2x~ipad.png ) ^
( -clone 0 -resize 2048x1536 -background #1f3165 -gravity center -extent 2048x1536 -write ../screen/ios/screen-ipad-landscape@2x.png ) ^
View config
swaplast = !git tag _invert && git reset --hard HEAD~2 && git cherry-pick _invert _invert~1 && git tag -d _invert
invertindex = !git commit -m tmp1 && git add -A && git commit -m tmp2 && git swaplast && git reset HEAD~1 && git reset HEAD~1 --soft
cleanup = !git clean -df
allclean = !git reset --hard && git cleanup
quickclean = !git checkout . & git cleanup
  • Original Stripe button


  • With Bootstrap 3 styles applied


View merge.js
* Recursively merge properties
* and return a new object
* `merge(a, b[, ...])`
* @return object
function merge() {
var dst = {},
View path.php
// Absolute
$path = current(preg_split('@(?<=public)@', getcwd()));
require_once "{$path}\includes\";
// Relative
$path = preg_split('/public/', getcwd());
$path = explode(DIRECTORY_SEPARATOR, trim(end($path), DIRECTORY_SEPARATOR));
require_once str_repeat('../', count($path)) . 'includes/';
  • Exclude dirs: .git|node_modules|vendor|storage|framework7|laravel-framework|cache
  • File Names match: *.env*|*.js|*.md|*.php|*css|*.xml|*.html|*.json|artisan|*.vue|*config|*access|*.bat|*.yml|*.ics|*.csv|*.xml|*.log|-*lock.*
View relative.php
function getRelativeTime($timestamp) {
$difference = strtotime(date('Y-m-d H:i:s')) - strtotime($timestamp);
$periods = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade'];
$lengths = [60, 60, 24, 7, 4.35, 12, 10];
// This was in the past
if ($difference >= 0) {
$ending = 'ago';
// This was in the future
View contextMenu.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Item MenuEntryName="Macro" MenuItemName="Select Current Line" />
<Item PluginEntryName="HTML Tag" PluginCommandItemName="Select tag contents only" ItemNameAs="Select Tag Contents" />
<Item MenuEntryName="Macro" MenuItemName="Delete Current Line" />
<Item MenuEntryName="Macro" MenuItemName="Remove Duplicate Lines" />
<Item id="0" />
<Item MenuEntryName="Macro" MenuItemName="Title Case" />
<Item MenuEntryName="Macro" MenuItemName="Sentence case." />