Skip to content

Instantly share code, notes, and snippets.

View jasny's full-sized avatar

Arnold Daniels jasny

View GitHub Profile
@jasny
jasny / .htaccess
Last active December 28, 2015 07:59
URL shortener
RewriteEngine On
RewriteRule ^(\w{5})$ /index.php?key=$1
@jasny
jasny / install-git-hooks
Last active January 2, 2016 22:59
Define git hooks within your repository. Allows defining multiple scripts for one hook.
#!/bin/bash
HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc"
HOOK_DIR=$(git rev-parse --show-toplevel)/.git/hooks
DIR=$(dirname "$0")
for hook in $HOOK_NAMES; do
# If the hook already exists, is executable, and is not a symlink
if [ ! -h "$HOOK_DIR/$hook" -a -x "$HOOK_DIR/$hook" ]; then
mv "$HOOK_DIR/$hook" "$HOOK_DIR/$hook.local"
fi
@jasny
jasny / phpbrew-php.sh
Created April 2, 2017 21:58
phpbrew-php automatically runs the correct PHP version for a project
#!/bin/bash
# phpbrew-php will determine the PHP version of the project from the NetBeans project or composer.json.
command_exists () {
type "$1" &> /dev/null ;
}
vergte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | tail -n1`" ]
@jasny
jasny / gist:453fcd74045d74559f4c04ad1938c36f
Last active September 14, 2017 14:03
Rinkeby address - Main account
0xfEBDC084cA75b7d053D22b93644d9D9A012f7859
@jasny
jasny / FooController.php
Last active July 11, 2018 16:05
Jasny Framework MVC
<?php
class FooController extends Controller
{
/**
* @var FooGateway
*/
protected $foos;
/**
@jasny
jasny / README.md
Last active August 14, 2018 10:50
New PHP library

Jasny {{library}}

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight BCH compliance Packagist Stable Version Packagist License

@jasny
jasny / authhash.php
Created May 9, 2012 17:20
Authentication without sessions in PHP
<?php
$secretword = "secret"; # Change this before use
$matches = null;
if (!empty($_REQUEST['AUTH']) && preg_match('/^(\w++):(\d++):(\w++)$/', $_REQUEST['AUTH'], $matches)) {
$username = str_rot13($matches[1]);
$time = (int)$matches[2];
$authhash = $matches[3];
$logged_in = md5($username . $time . $secretword) === $authhash && $time >= time() - 3000;
}
@jasny
jasny / livecontract-yaml-to-json.php
Created June 13, 2019 17:04
Script to convert Live Contract scenario Yaml to JSON
<?php
$file = $argv[1];
$tagToStruct = function($value, $tag) {
$key = substr($tag, 1);
return ["<$key>" => $value];
};
$callbacks = [
@jasny
jasny / poc-standard.php
Created June 26, 2019 07:16
Proof of concept where `strict_types` affects `==` and `!=` operators
<?php
var_dump("1" == 1);
var_dump("1" != 1);
@jasny
jasny / Email.php
Created September 4, 2019 10:52
Use Twig with PHPMailer
<?php
/**
* Render and send e-mail
*/
class Email extends PHPMailer
{
/**
* @var Twig_Environment
*/