Skip to content

Instantly share code, notes, and snippets.

🐚
call me on my #!/bin/sh phone

Matt Loberg mloberg

🐚
call me on my #!/bin/sh phone
View GitHub Profile
@mloberg
mloberg / Lockout.php
Created May 6, 2020
Track login attempts and prevent brute forcing
View Lockout.php
<?php
declare(strict_types=1);
namespace App\Security;
use DateTimeImmutable;
use Generator;
use Predis\Client;
@mloberg
mloberg / media.sh
Created Jun 17, 2019
Batch convert media files
View media.sh
#!/usr/bin/env bash
set -e
# convert and optmize jpg files to png & gif
# requires imagemagick (brew install imagemagick)
while read -r file; do
echo ">> resizing/converting $file"
name="${file%.*}"
convert "$file" -resize 1600 -quality 85 -strip "${name}.jpg"
convert "$file" -quality 85 -strip -colors 256 "${name}.png"
View gist:467536d2b6a1eb3c92a13b804faedd78
### Keybase proof
I hereby claim:
* I am mloberg on github.
* I am mloberg (https://keybase.io/mloberg) on keybase.
* I have a public key ASDcFyl0kafbvzkZ9nI-2-9d5Kk5XQMLUTnjNRw5p5s_DAo
To claim this, I am signing this object:
View batch.py
from itertools import islice, chain
def batch(iterable, size):
iterator = iter(iterable)
for first in iterator:
yield chain([first], islice(iterator, size - 1))
@mloberg
mloberg / npm.sh
Created Apr 21, 2017
WIP: Run npm via Docker
View npm.sh
npm () {
[ -n "$NODE_VERSION" ] || NODE_VERSION="latest"
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
@mloberg
mloberg / mphp
Created Oct 3, 2016
Bash script for managing PHP versions on macOS (using Homebrew)
View mphp
#!/usr/bin/env bash
#
# Copyright (c) 2016 Matthew Loberg
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
#
# ==========================
# Manage PHP (uses Homebrew)
# ==========================
#
# Commands:
View comparison.php
<?php
function compareHashes($hashOne, $hashTwo)
{
$result = 0;
for ($i = 0; $i < strlen($hashOne); $i++) {
$charOne = substr($hashOne, $i, 1);
$charTwo = substr($hashTwo, $i, 1);
$intOne = base_convert($charOne, 16, 10);
View FormCollectionView.js
/**
* @fileOverview Form collection handler
*
* @author Matthew Loberg
*/
define(function(require, module, exports) {
'use strict';
var $ = require('jquery');
@mloberg
mloberg / nginx.conf.erb
Created Mar 12, 2015
Boxen PHP Project Module
View nginx.conf.erb
<%# modules/common/templates/nginx.conf.erb %>
# Example template for PHP-FPM based projects
#
# The template which nginx uses within a boxen::project can be overridden
# to a specific template such as this one.
#
# You will likely need to change both the root and SCRIPT_FILENAME parameters below
# to match your setup
#
server {
@mloberg
mloberg / flickr.php
Created Oct 21, 2014
Display Flickr photos
View flickr.php
<?php
$id = '30065870@N08'; // Find your Flickr ID at http://idgettr.com
$url = 'http://api.flickr.com/services/feeds/photos_public.gne?id='.$id.'&format=json';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
// Remove jsonp callback (jsonFlickrFeed) and escaped characters (except ")
You can’t perform that action at this time.