Skip to content

Instantly share code, notes, and snippets.

View iolloyd's full-sized avatar
💭
Busy bee

Lloyd Moore iolloyd

💭
Busy bee
View GitHub Profile
@iolloyd
iolloyd / slim.php
Created August 8, 2016 15:10
How slim v3 makes the app available in the callback
public function add(\Slim\Middleware $newMiddleware)
{
if(in_array($newMiddleware, $this->middleware)) {
$middleware_class = get_class($newMiddleware);
throw new \RuntimeException("Circular Middleware setup detected. Tried to queue the same Middleware instance ({$middleware_class}) twice.");
}
$newMiddleware->setApplication($this);
$newMiddleware->setNextMiddleware($this->middleware[0]);
array_unshift($this->middleware, $newMiddleware);
}
@iolloyd
iolloyd / uuid_indexing.conf
Created July 12, 2016 16:33
Replacing uuids with incremental integers
sql_query_pre = SET @x = 0
# Since we have a uuid as an id, we need to swap that out
# for an integer
sql_query = \
SELECT \
@x := @x + 1 as id, user_id, type, name, email, browser, question, unix_timestamp(created) as created \
FROM \
contacts
@iolloyd
iolloyd / package_control.py
Created July 7, 2016 07:58
package control for sublime text 3
import hashlib
import os
import urllib.request
pf = 'Package Control.sublime-package'
packages_path = sublime.installed_packages_path()
proxy_handler = urllib.request.ProxyHandler()
opener = urllib.request.build_opener(proxy_handler)
urllib.request.install_opener(opener)
@iolloyd
iolloyd / dict.sh
Last active September 7, 2016 15:23
Bash / zsh key value map
#!/bin/sh
pre=$(basename $0)
# the -d flag makes a directory in place of a file
# the -t flag uses the pre variable as a template
dir=$(mktemp -dt ${pre})
getmap() {
# Make sure we have both a map name and key
@iolloyd
iolloyd / sphinx.conf
Created June 30, 2016 16:17
Example configuration for sphinx
source base
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = root
sql_db = lookbooks_live
sql_port = 3306
}
@iolloyd
iolloyd / reset_mysql_root_password.md
Created June 21, 2016 14:01
How to reset mysql root password
sudo /usr/local/mysql/support-files/mysql.server stop

sudo mysqld_safe --skip-grant-tables

mysql -u root

UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

FLUSH PRIVILEGES;
sudo /usr/local/mysql/support-files/mysql.server stop

sudo mysqld_safe --skip-grant-tables

mysql -u root

UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

FLUSH PRIVILEGES;
@iolloyd
iolloyd / Caddyfile
Created May 19, 2016 17:23
A configuration file for caddy to serve a php site through a front loader using index.php
///////////////////////////////////////////////
// This is all you need. Just add the following
// into a file called Caddyfile.
//
// Then just run `caddy`
//
// This example assumes ./public/index.php
///////////////////////////////////////////////
localhost:9999 {
@iolloyd
iolloyd / packet_sniff.c
Created May 1, 2016 22:15
sniff packets in c
int main()
{
int dsize, saddr_size;
struct sockaddr saddr;
struct in_addr in;
unsigned char *buf = (unsigned char *)malloc(65536);
if((raw_socket = socket(AF_INET , SOCK_RAW , IPPROTO_TCP) < 0)
{
@iolloyd
iolloyd / just_alphas.php
Created April 26, 2016 07:26
an example of how to check for just letters without preg_match in php
<?php
function isValid($string) {
if (ctype_alpha($string)) {
return true;
} else {
return false;
}
}
// This returns true, just letters