Skip to content

Instantly share code, notes, and snippets.

View kevindees's full-sized avatar
🎯
Focusing

Kevin Dees kevindees

🎯
Focusing
View GitHub Profile
@kevindees
kevindees / binary.php
Last active July 27, 2018 07:48
Faster user role detection when passing requirements as a string
<?php
class User {
const ROLE_GUEST = 2;
const ROLE_SHOPPER = 4;
const ROLE_ADMIN = 8;
const ROLE_SUPER = 16;
}
function has_role($role, $roles) {
return $role & $roles;
<?php
list($script, $uri, $n) = $argv;
$s = microtime(true);
function dispatch($uri, $routes) {
$path = explode('/', trim($uri, '/'));
$c = count($path);
foreach ($routes as $i => $route) {
// $r = explode('/', $route[0][0]); almost no diff event with explode on / if not using an array
$r = $route[0];
@kevindees
kevindees / .zshrc
Last active September 28, 2017 22:04
# my commands
alias ll="ls -alh"
# include .bashrc if it exists
if [ -f $HOME/Dropbox/Dev/Profiles/mac_bash ]; then
. $HOME/Dropbox/Dev/Profiles/mac_bash
fi
# include .bashrc if it exists
if [ -f $HOME/Dropbox/Dev/Profiles/common_bash ]; then
@kevindees
kevindees / helper_functions.php
Last active November 29, 2017 02:57
This is a code snippet of a framework I'm working on that I'm creating
<?php
/**
* Autoload PSR4 Classes
*
* @param array $map map auto loaders, initializer, and class map to avoid file exists checks
* @param string|null $cache_prefix cache the init files as one file.
*/
function autoload_psr4(array &$map = [], ?string $cache_prefix = null) {
if(isset($map['init']) && empty($cache_prefix) ) {
@kevindees
kevindees / web_test.sh
Created July 29, 2017 02:17
Measuring the average website response time with cURL http://cacodaemon.de/index.php?id=11
#!/bin/bash
URL="$1"
MAX_RUNS="$2"
SUM_TIME="0"
i="0"
while [ $i -lt $MAX_RUNS ]; do
TIME=`curl $URL -o /dev/null -s -w %{time_total}`
TIME="${TIME/,/.}"
function spaceCard(str) {
var ret = [];
var i;
var len;
str = str.replace(/\s|\D+/gi, '');
if( str.match(/^3[47]/) ) {
// american express only
var sec = 4;
@kevindees
kevindees / Vagrantfile
Last active June 23, 2016 21:08
vagrant bootstrap wp site
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provider "virtualbox"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.provider :virtualbox do |vb|
@kevindees
kevindees / install-wp.sh
Created January 18, 2016 13:47
Install WordPress, vhost and DB on a Ubuntu bash script
#!/bin/bash
#
# Install WordPress on a Ubuntu 13+ VPS
#
# run as root
if [[ $UID != 0 ]]; then
echo "Please run this script with sudo:"
echo "sudo $0 $*"
exit 1
#!/usr/bin/env bash
apt-get update
apt-get -y upgrade
apt-get install -y debconf-utils
export DEBIAN_FRONTEND="noninteractive"
# tools
apt-get -y install git