Skip to content

Instantly share code, notes, and snippets.

View jonpemby's full-sized avatar

Jonathon Pemberton jonpemby

  • Chewy, Inc
  • Salem, MA
View GitHub Profile
@jonpemby
jonpemby / random_string_from_list.sql
Created March 5, 2018 15:33
PostgreSQL random string from list
select (array['hello', 'world'])[trunc(1 + random() * @len)];
@jonpemby
jonpemby / date_to_input_value.js
Created March 5, 2018 19:00
Format a JavaScript date for HTML5 "date" input value
document.querySelector('.datepicker').value = (new Date()).toISOString().substr(0, 10);
@jonpemby
jonpemby / scandir.lua
Created March 6, 2018 02:14
Lua scandir implementation
-- Lua implementation of PHP scandir function
-- special thanks to:
-- rhoster (https://stackoverflow.com/users/974053/rhoster)
-- ulmangt (https://stackoverflow.com/users/1212363/ulmangt)
function scandir(directory)
local i, t, popen = 0, {}, io.popen
local pfile = popen('ls -a "'..directory..'"')
for filename in pfile:lines() do
i = i + 1
t[i] = filename
@jonpemby
jonpemby / random_string_from_list.sql
Last active March 7, 2018 16:19
MySQL random string from list
select elt(floor(1 + (rand() * @len)), "hello", "world", "this", "is", "a", "random", "list");
@jonpemby
jonpemby / get_required.sql
Last active March 15, 2018 18:22
MySQL find all required columns from table
select * from information_schema.COLUMNS
where TABLE_SCHEMA = 'schema'
and TABLE_NAME = 'table' -- optionally specify the table
and IS_NULLABLE = 'NO' -- optionally set to 'YES' to find nullable columns
and COLUMN_DEFAULT is null; -- optionally specify columns without a default
@jonpemby
jonpemby / allEmpty.js
Created March 16, 2018 14:45
JavaScript one liner to determine if multiple strings/arrays are empty
export default (...fields) => [...fields].reduce((sum, { length }) => sum + length, 0) === 0;
@jonpemby
jonpemby / 1-add-macros.php
Created March 28, 2018 14:33 — forked from adamwathan/1-add-macros.php
Multiformat Endpoints in Laravel
<?php
namespace App\Providers;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Support\ServiceProvider;
use App\Http\Middleware\CaptureRequestExtension;
class AppServiceProvider extends ServiceProvider
#!/usr/bin/env bash
#
# ... commands ...
#
exit $?
@jonpemby
jonpemby / MySQL_InnoDB_Engine_Status.sql
Created April 27, 2018 20:37
MySQL InnoDB engine status
SHOW ENGINE INNODB STATUS;
@jonpemby
jonpemby / collection-peekMap.php
Created May 9, 2018 19:42
Collection macro to peek backwards at the last value in a map.
Collection::macro('peekMap', function (callable $callback) {
$lastValue = null;
return $this->map(function ($value, $key) use ($callback, $lastValue) {
$newValue = $callback($value, $key, $lastValue);
$lastValue = $newValue;
return $newValue;
});
});