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 / find_duplicates.py
Last active March 15, 2019 13:51
Find duplicate integers in Python
def find_duplicates(nums):
sorted_nums = sorted(nums)
last = None
dups = []
for n in sorted_nums:
if last and n == last:
try:
last_dup = dups[-1]
except IndexError:
@jonpemby
jonpemby / main.kt
Created March 12, 2019 00:04
Kotlin parseInt
fun parseInt(s: String): Int {
var num = 0
var j = 1
var i = s.length - 1
while (i >= 0) {
val c = s[i].toInt()
if (c < 48 || c > 58) {
i -= 1
@jonpemby
jonpemby / artisan-queue.conf
Last active December 14, 2018 00:18
Set up supervisor for Laravel queues
# Place in: /etc/supervisor/conf.d/artisan-queue.conf
[program:artisan-queue]
commmand=php /var/www/html/artisan queue:work
autostart=true
autorestart=true
# Can add this if you want a non-laravel log file
# stderr_logfile=/var/www/html/storage/logs/queue_err.log
# stdout_logfile=/var/www/html/storage/logs/queue_out.log
@jonpemby
jonpemby / postgres.sh
Created December 13, 2018 01:11
Set up Postgres on Ubuntu
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Add repository
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
# Install
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
@jonpemby
jonpemby / capitalize.sql
Created May 17, 2018 16:47
Capitalize a string in MySQL
DELIMITER $$
-- Capitalizes a word
-- @param str VARCHAR String to capitalize
-- @return VARCHAR Capitalized string
CREATE FUNCTION CAPITALIZE(str VARCHAR(255)) RETURNS VARCHAR(255)
BEGIN
RETURN CONCAT(UPPER(SUBSTRING(str, 1, 1)), SUBSTRING(str, 2));
END$$
DELIMITER ;
@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;
});
});
@jonpemby
jonpemby / MySQL_InnoDB_Engine_Status.sql
Created April 27, 2018 20:37
MySQL InnoDB engine status
SHOW ENGINE INNODB STATUS;
#!/usr/bin/env bash
#
# ... commands ...
#
exit $?
@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
@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;