Skip to content

Instantly share code, notes, and snippets.

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

Matt Loberg mloberg

🐚
call me on my #!/bin/sh phone
View GitHub Profile
@mloberg
mloberg / gist:3750653
Created September 19, 2012 16:35
Find file in git based on md5 checksum.
View gist:3750653
#!/bin/sh
CHECKSUM=$1
FILE=$2
if [[ -z "$CHECKSUM" ]]; then
echo "Usage: $0 md5 file"
exit 1
elif [[ -z "$FILE" ]]; then
echo "Usage: $0 md5 file"
@mloberg
mloberg / mysql.php
Created August 30, 2011 18:00
Simple PHP MySQL Class
View mysql.php
<?php
class Mysql{
static private $link = null;
static private $info = array(
'last_query' => null,
'num_rows' => null,
'insert_id' => null
);
@mloberg
mloberg / sshb0t.service
Last active October 3, 2021 02:53
Raspberry Pi Setup
View sshb0t.service
# /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
View Lockout.php
<?php
declare(strict_types=1);
namespace App\Security;
use DateTimeImmutable;
use Generator;
use Predis\Client;
@mloberg
mloberg / gist:2937062
Created June 15, 2012 15:33
Replace local links in markdown ([[link]]) with normal links ([link](link)).
View gist:2937062
#!/bin/sh
PREFIX=wiki
FILES=$(find . -type f -iname '*.md' -o -iname '*.markdown')
if [[ "$1" == "revert" ]]; then
# To Parse back to normal local [[links]]
for file in $FILES; do
sed -e 's/\[\(.*\)\](\/$PREFIX\/\(.*\))/[[\1]]/g' $file > $file.tmp
mv $file.tmp $file
@mloberg
mloberg / irc.rb
Created April 9, 2012 17:56
Ruby IRC
View irc.rb
require "socket"
class IRC
def initialize(info)
@server = info[:server]
@port = info[:port] || 6667
@password = info[:password]
@nick = info[:nick]
@channel = info[:channel]
@mloberg
mloberg / gist:2852153
Created June 1, 2012 13:28
MySQL Slow Query Log Analyzer
View gist:2852153
#!/usr/bin/php
<?php
/**
* The Analyzer class.
*/
class Analyzer {
private $fp;
@mloberg
mloberg / File.Upload.js
Created November 6, 2011 04:23
MooTools Ajax File Upload
View File.Upload.js
/*
name: [File.Upload, Request.File]
description: Ajax file upload with MooTools.
license: MIT-style license
author: Matthew Loberg
requires: [Request]
provides: [File.Upload, Request.File]
credits: Based off of MooTools-Form-Upload (https://github.com/arian/mootools-form-upload/) by Arian Stolwijk
@mloberg
mloberg / media.sh
Created June 17, 2019 23:34
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"
@mloberg
mloberg / example.php
Created March 10, 2011 19:27
A simple Postmark PHP Class
View example.php
<?php
require("postmark.php");
$postmark = new Postmark("your-api-key","from-email","optional-reply-to-address");
if($postmark->to("reciver@example.com")->subject("Email Subject")->plain_message("This is a plain text message.")->send()){
echo "Message sent";
}