Skip to content

Instantly share code, notes, and snippets.

View elazar's full-sized avatar

Matthew Turland elazar

View GitHub Profile
@elazar
elazar / PasswordIterator.php
Created November 6, 2011 04:55
Iterator to generate sequential passwords within a given length range
<?php
/**
* Iterator to generate sequential passwords within a given length range.
*/
class PasswordIterator implements Iterator
{
/**
* Length of the next password to be generated
* @var int
*/
@elazar
elazar / example.php
Created February 15, 2012 02:54
Delayed route loading in Slim
<?php
require_once 'Slim/Slim.php';
class Custom_Route extends Slim_Route {
public function dispatch() {
$this->setCallable(require $this->getCallable());
return parent::dispatch();
}
}
@elazar
elazar / domain.py
Created April 7, 2012 03:12
Python domain checker
#!/usr/bin/env python
import sys
import socket
import itertools
def filter_tlds(x): return x.startswith(".")
tlds = set(filter(filter_tlds, sys.argv[1:]))
non_tlds = set(sys.argv[1:]).difference(tlds)
@elazar
elazar / .gitconfig
Created May 1, 2012 18:53
git mem/rec bash aliases
; These aliases are only useful if you work from a directory containing multiple repos.
; mem stores the current branch or commit checked out per repo to a specified file.
; rec reads a specified file in this format and restores the repos to their respective branches or commits.
; This is useful if you're working on or testing multiple branches together and/or simultaneously.
;
; Example:
; git mem /path/to/file
; [change repo configurations, do work, etc.]
; git rec /path/to/file
; [repos are now back in the configuration they were in when git mem was run]
@elazar
elazar / phpunit-log-junit.php
Created May 25, 2012 23:43
PHPUnit --log-junit processor
<?php
/**
* This script is used to process the output of a PHPUnit test run
* that uses --log-junit for the purposes of timing each executed
* test method. It outputs test methods with their respective
* runtimes in order from largest to smallest. Times are in
* seconds. The script accepts paths to any number of files in the
* JUnit log format.
*
* Ex: php phpunit-log-junit.php /path/to/junit-log1.xml /path/to/junit-log2.xml ...
@elazar
elazar / PasswordGenerator.php
Last active January 27, 2023 15:20
Password Iterator vs GeneratorOriginal commented password iterator implementation: https://gist.github.com/elazar/1342491
<?php
function PasswordGenerator($min = 1, $max = null)
{
$ord = range(32, 126);
$chr = array_map('chr', $ord);
$first = reset($chr);
$last = end($chr);
$length = $min;
$password = array_fill(0, $length, $first);
$stop = array_fill(0, $length, $last);
@elazar
elazar / dbutil.md
Last active August 29, 2015 14:02
Database utility I want

Let's imagine that you've got information for accessing several different databases you have to work with on a regular basis. Servers (e.g. mysql, pgsql, etc.), hostnames, ports, usernames, password files, database names, etc.

Let's also imagine that there are several programs you use on these databases regularly. If you use MySQL, this might include the mysql CLI client, the mysqldump utility, and liquibase for versioning.

Manually typing these commands together with this database information is tedious. Managing shorthand shell functions for the same purpose also seems suboptimal.

What I want is a wrapper utility of sorts to which I can specify the program I want to run and the name of (or potentially a shorthand alias for) the database I want to run it on, and have it pull all other information from a configuration file I create to derive and run the resulting CLI command.

Here's a hypothetical example of such a file:

@elazar
elazar / Dockerfile
Created November 10, 2015 03:21
Fireplace Dockerfile
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update && apt-get -y install python3 python3-pip git
RUN pip3 install virtualenv
RUN virtualenv ~/venv
RUN ~/venv/bin/pip install -e git+https://github.com/jleclanche/fireplace.git#egg=fireplace
RUN . ~/venv/bin/activate ; cd ~/venv/src/fireplace && pip3 install -r requirements.txt && ./bootstrap.sh && ./setup.py install && py.test
RUN echo '. ~/venv/bin/activate ; cd ~' >> ~/.bashrc
@elazar
elazar / .zshrc
Last active February 20, 2020 23:19
git aliases
alias ga="git add"
alias gai="git add --interactive"
alias gb="git branch"
alias gbd="git branch -D"
alias gc="git commit"
alias gca="git commit --amend"
alias gcm="git commit -m"
alias gco="git checkout"
alias gcob="git checkout -b"
alias gd="git diff"
@elazar
elazar / jefferson.php
Last active January 12, 2018 03:34
Jefferson cipher
<?php
function jefferson(string $message)
{
$letters = array_merge(range('a', 'z'), ['_']);
$numbers = range(1, 26);
$cipher = [];
foreach ($numbers as $number) {
$cipher[$number] = [];
foreach ($letters as $index => $letter) {