Skip to content

Instantly share code, notes, and snippets.

@fredsted
fredsted / retry.php
Created July 24, 2019 12:12
Retry all failed laravel jobs without causing a memory leak
<?php
$pdo = new PDO(
sprintf(
'mysql:host=%s;dbname=%s',
getenv('DB_HOST'),
getenv('DB_DATABASE')
),
getenv('DB_USERNAME'),
getenv('DB_PASSWORD')
);
@fredsted
fredsted / ec2-iam-role.json
Created February 7, 2018 10:57
EC2 Discovery not working in ES 6.1/6.2
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1493803477000",
"Effect": "Allow",
"Action": [
"ec2:DescribeAvailabilityZones",
"ec2:DescribeInstances",
"ec2:DescribeRegions",
@fredsted
fredsted / autodelete.sh
Created August 28, 2017 07:04
Script to delete old files when disk getting full
#/bin/sh
# This script deletes old files when the disk is getting full.
# It will always delete the oldest file or directory. Can be run
# in a cronjob every few minutes.
# Configurables
STORAGEDIR=/var/backups
#!/usr/bin/python
# Installation:
# - Install `boto`: pip install -U boto
# - Configure EC2 credentials: see http://boto.cloudhackers.com/en/latest/getting_started.html#configuring-boto-credentials
# - Configure username or SSH args below
# These things are configurable
region = 'eu-central-1'
ssh_username = 'simonfredsted'
@fredsted
fredsted / webhook.php
Created February 12, 2016 15:02
PHP Webhook Testing script – logs webhook requests
<?php
$input = file_get_contents('php://input');
$input = (empty($input) ? 'No content' : $input);
$http_method = $_SERVER['REQUEST_METHOD'];
$http_url = $_SERVER['REQUEST_URI'];
$ip = $_SERVER['REMOTE_ADDR'];
$datetime = date('r');
$headers = '';
@fredsted
fredsted / hetzner_inventory_ansible.php
Created November 2, 2015 13:02
Hetzner Robot Ansible inventory script
#!/usr/bin/php
<?php
define('HETZNER_KEY_PATH', '/root/.hetzner_robot_key');
if (!file_exists(HETZNER_KEY_PATH)) die('Key file at '.HETZNER_KEY_PATH.' not found'.PHP_EOL);
$hetzner_key = file_get_contents(HETZNER_KEY_PATH);
if (!strpos($hetzner_key, ':')) die('Key file must be of format "username:password"'.PHP_EOL);
$process = curl_init('https://robot-ws.your-server.de/server');
curl_setopt($process, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
@fredsted
fredsted / ddns-api.php
Last active December 15, 2022 20:41
Virtualmin Dynamic DNS (DDNS) server
<?php
// This script receives DDNS updates via HTTP
// example: http://server/ddns-api.php?name=home = updates home.domain.com to IP of requester
define('DDNS_DATA_FILE', '/home/ddns/ddns.json');
define('DDNS_DOMAIN', 'example.com');
header("Content-type: text/plain");
@fredsted
fredsted / gist:f51bcc9c25e9ebe5c392
Last active August 29, 2015 14:03
VikingBot NickServ Plugin
<?php
/*
VikingBot NickServ Plugin
To install, put this file in your /plugins directory.
Then append the following to your vikingbot config.php
replacing the nickname and password with your actual
nickserv details. Then restart the bot.
@fredsted
fredsted / css-mac-button.html
Last active October 9, 2020 23:06
Mac OS X-style button in CSS, live: http://mu.ms/f/tc.html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.osxbutton {
text-decoration: none;
font-family:".LucidaGrandeUI", "Lucida Grande", "Lucida sans unicode";
color: black;
font-size: 11px;
padding: 1px 7px;