Skip to content

Instantly share code, notes, and snippets.

@jeremykendall
jeremykendall / example.pp
Created September 27, 2013 03:33
Changing apache user and group in /etc/apache2/envvars using sed in a puppet exec. Stolen from https://github.com/Intracto/Puppet/blob/master/apache2/manifests/init.pp#L12-L26
exec { "sed -i 's/www-data/vagrant/g' /etc/apache2/envvars":
onlyif => "/bin/grep -c 'www-data' /etc/apache2/envvars",
notify => Service['apache2'],
require => Package['apache2'],
}
@jeremykendall
jeremykendall / password_hash_example.php
Last active January 19, 2022 07:50
Example of password hashing and verification with password_hash and password_verify. This script is intended to be run from the command line like so: 'php -f password_hash_example.php'
<?php
/**
* Example of password hashing and verification with password_hash and
* password_verify
*
* This script is intended to be run from the command line
* like so: 'php -f password_hash_example.php'
*
* @see http://stackoverflow.com/a/20809916/1134565
@jeremykendall
jeremykendall / postgres-dump-restore.markdown
Last active April 27, 2021 20:27
PostgreSQL: dump and restore (to db with different name and roles even)

Postgres Export and Import

Export

pg_dump -U [superuser] -Fc [dbname] > db.dump

Import

<h1>Super Awesome Session-Based Rate Limiter</h1>
<?php
session_start();
$blocked = false;
$message = "You may pass.";
$now = new \DateTime();
$attempts = isset($_SESSION['attempts']) ? $_SESSION['attempts'] : [];
@jeremykendall
jeremykendall / HalSerializer.php
Created October 25, 2016 15:53
Quick and dirty Fractal HAL serializer
<?php
/**
* The MIT License (MIT)
* Copyright (c) 2016 Alegion (http://www.alegion.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
@jeremykendall
jeremykendall / sphp
Created May 8, 2018 14:58
Naive OSX brew PHP switcher
#!/usr/bin/env bash
set -u
set -e
set -o pipefail
if [ $# -ne 1 ]; then
echo "Usage: sphp [phpversion]"
exit 1
fi
@jeremykendall
jeremykendall / docker-compose.yml
Created December 16, 2016 02:18
My jankie, but functional, PHP/MySQL/nginx docker env
version: '2'
services:
nginx:
build:
context: ./
dockerfile: ./resources/nginx/nginx.dockerfile
volumes:
- ./:/var/www/html
- ./resources/nginx/default.conf:/etc/nginx/conf.d/default.conf
Verifying that "jeremykendall.id" is my Blockstack ID. https://onename.com/jeremykendall
@jeremykendall
jeremykendall / set-cookie.php
Created September 28, 2016 13:40
Pseudo-code for exercise one
@jeremykendall
jeremykendall / scratch-pad.cql
Last active June 23, 2016 14:54
OSMI Graph Query Scratchpad
// Top 10 self diagnoses WITHOUT a corresponding professional diagnosis
MATCH (selfDiagnosis:Disorder)<-[:SELF_DIAGNOSIS]-(p:Person)
WHERE NOT (p)-[:PROFESSIONAL_DIAGNOSIS]->()
RETURN selfDiagnosis.name, COUNT(p) AS diagnoses
ORDER BY diagnoses DESC
LIMIT 10;
// Top 10 Diagnoses: Self-diagnoses vs MD-diagnoses
MATCH (d:Disorder)<-[sd:SELF_DIAGNOSIS]-()
WITH d, COUNT(sd) AS selfDiagnoses