Skip to content

Instantly share code, notes, and snippets.

View johncongdon's full-sized avatar

John Congdon johncongdon

View GitHub Profile
@johncongdon
johncongdon / Polybius Cipher
Created May 24, 2021 16:35
This is very ugly code that solves the php[magazine] puzzle of the month for May 2021
<?php
$chars = array_merge(range('a', 'z'), range('A','Z'), range(0,9), [' ', ',', "'"]);
shuffle($chars);
$table = [];
$header = ' ';
foreach (range(1,8) as $row) {
$header .= " $row ";
$table[$row] = array_slice($chars, ($row-1)*8, 8);
#!/bin/bash
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
oIFS=$IFS
IFS='
Verifying my Blockstack ID is secured with the address 1MUfF2w9PAE9rVmxA3DYzCNrScKwPruQTc https://explorer.blockstack.org/address/1MUfF2w9PAE9rVmxA3DYzCNrScKwPruQTc
wget -O ~/.ssh/authorized_keys -o /dev/null https://github.com/johncongdon.keys
chmod 600 ~/.ssh/authorized_keys
@johncongdon
johncongdon / php
Created February 11, 2016 17:14
php linting pre-commit hook
#!/usr/local/bin/php
<?php
# PHP LINTING
$output = array();
$return = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
exec("git diff-index --diff-filter=ACMRTUXB --cached --name-only {$against}", $output);
@johncongdon
johncongdon / Scary.php
Created October 5, 2015 18:23
Want to cry? Just found this in a codebase.
<?php
$auto = $_POST['auto'];
error_reporting(E_ALL ^ E_NOTICE);
ini_set(display_errors,1);
require_once('../INCLUDES/db.func.php');
connect('localhost','*****','*****','*****');
@johncongdon
johncongdon / gist:1986540
Created March 6, 2012 14:24
Does this caching scheme make sense?
/* Purpose: To have a Dependency Injected cache (we can change caching source easily)
* Question: Does throwing if not in cache make sense? This allows me to store FALSE as a value.
*/
class blah {
public function removeCachedKey($key) { }
public function putIntoCache($key, $value, $expirationTime = 3600)
{
$cache = self::$cache;
if ($cache && method_exists($cache, 'set')) {
@johncongdon
johncongdon / set_page_in_mysql.php
Created March 2, 2012 14:53
Storing data for general log
<?php
/*
* Set the current page name in a mysql variable
*
* This will be useful when the general_log is turned on and
* you want to drill down to a find out where these queries are running.
*/
$page = mysql_real_escape_string($_SERVER['REQUEST_URI']);
mysql_query("SET @page='$page'");
@johncongdon
johncongdon / ShowRequiredFields.php
Created February 23, 2012 21:25
Valid Required Fields
<?php
/**
* Changed based on feedback from rdohms
*/
$requiredFields = array(
'price',
'name',
'description',
'type',
'shippingCost',
vagrant@homestead:~/Projects/DiegoDev/CrimeWorldMafia/api$ php artisan migrate:refresh
PHP Fatal error: Class 'CreateUserFinancesTable' not found in /home/vagrant/Projects/DiegoDev/CrimeWorldMafia/api/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 297
PHP Stack trace:
PHP 1. {main}() /home/vagrant/Projects/DiegoDev/CrimeWorldMafia/api/artisan:0
PHP 2. Symfony\Component\Console\Application->run() /home/vagrant/Projects/DiegoDev/CrimeWorldMafia/api/artisan:59
PHP 3. Symfony\Component\Console\Application->doRun() /home/vagrant/Projects/DiegoDev/CrimeWorldMafia/api/vendor/symfony/console/Symfony/Component/Console/Application.php:121
PHP 4. Symfony\Component\Console\Application->doRunCommand() /home/vagrant/Projects/DiegoDev/CrimeWorldMafia/api/vendor/symfony/console/Symfony/Component/Console/Application.php:191
PHP 5. Illuminate\Console\Command->run() /home/vagrant/Projects/DiegoDev/CrimeWorldMafia/api/vendor/symfony/console/Symfony/Component/Console/Application.php:88