Skip to content

Instantly share code, notes, and snippets.

View mloberg's full-sized avatar
🐚
call me on my #!/bin/sh phone

Matt Loberg mloberg

🐚
call me on my #!/bin/sh phone
View GitHub Profile
@mloberg
mloberg / sshb0t.service
Last active October 3, 2021 02:53
Raspberry Pi Setup
# /etc/systemd/system/sshb0t.service
[Unit]
Description=Sync ssh keys
After=network.target
[Service]
Type=simple
User=mloberg
WorkingDirectory=/home/mloberg
ExecStart=/usr/local/bin/sshb0t --interval 1h --user mloberg
@mloberg
mloberg / Lockout.php
Created May 6, 2020 17:29
Track login attempts and prevent brute forcing
<?php
declare(strict_types=1);
namespace App\Security;
use DateTimeImmutable;
use Generator;
use Predis\Client;
@mloberg
mloberg / media.sh
Created June 17, 2019 23:34
Batch convert media files
#!/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"
### 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:
@mloberg
mloberg / batch.py
Created March 2, 2018 20:09
Python Tools
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 April 21, 2017 23:00
WIP: Run npm via Docker
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 October 3, 2016 19:45
Bash script for managing PHP versions on macOS (using Homebrew)
#!/usr/bin/env bash
#
# Copyright (c) 2016 Matthew Loberg
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
#
# ==========================
# Manage PHP (uses Homebrew)
# ==========================
#
# Commands:
<?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);
/**
* @fileOverview Form collection handler
*
* @author Matthew Loberg
*/
define(function(require, module, exports) {
'use strict';
var $ = require('jquery');
@mloberg
mloberg / nginx.conf.erb
Created March 12, 2015 01:19
Boxen PHP Project Module
<%# 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 {