Skip to content

Instantly share code, notes, and snippets.

'); DROP TABLE statuses; --

Ian Littman iansltx

'); DROP TABLE statuses; --
Block or report user

Report or block iansltx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:6d0181c835e5afbf2965
class MyQuery {
protected function buildCollectionQuery($is_count_query = false) {
$qs = $is_count_query ? $this->baseCountQS : $this->baseCollectionQS;
$qsParams = [''];
if ($this->showInactive === false) {
$qs .= " && u.userStatus = 'active'";
iansltx /
Last active Aug 29, 2015
Get a list of all primitive Pythagorean triples with hypotenuse <= Nmax, one per line
# pass the MB of RAM you want to use as your argument
# Nmax = 10,000 * RAM_in_MB; CPU time on an EC2 r3.8xlarge is 60s/1M Nmax
# adapted from
import sys
from numpy import mat, array
def gen_pythagorean_triples(max):
u = mat(' 1 2 2; -2 -1 -2; 2 2 3')
a = mat(' 1 2 2; 2 1 2; 2 2 3')
d = mat('-1 -2 -2; 2 1 2; 2 2 3')
iansltx / MyAction.php
Created Jul 18, 2014
On-construct ADR content type negotiation
View MyAction.php
class MyAction
protected $request;
protected $responder;
public function __construct(Aura\Web\Request $request, ResponderInterface $responder) {
// you'd inject other stuff here normally, but let's assume that this is extended elsewhere
$this->request = $request;
iansltx / transform.php
Created Aug 12, 2014
Toggl CSV -> grouped by description and project + decimal hours QDPA
View transform.php
$filename = $argv[1];
if (!file_exists($filename))
die("file not found\n");
$rows = explode("\n", str_replace(["\r\n", "\r"], "\n", trim(file_get_contents($filename))));
$headers = str_getcsv(array_shift($rows));
$data = array_map(function($row) use ($headers) {return array_combine($headers, str_getcsv($row));}, $rows);
usort($data, function($a, $b) {return strtotime($a['Start date']) > strtotime($b['Start date']) ? 1 : -1;});
iansltx / phpexcel_convenience.php
Last active Aug 29, 2015
PHPExcel Convenience Functions
View phpexcel_convenience.php
<?php // use as-is with PHPExcel, or build a utility class around them
// $addColumn($sheet, 'A', 1, ['value_in_A1', 'value_in_A2']);
$addColumn = function(\PHPExcel_Worksheet $worksheet, $column, $row, $values) {
for ($i = 0, $count = count($values); $i < $count; $i++, $row++)
$worksheet->getCell($column . $row)->setValue($values[$i]);
// $addRow($sheet, 'A', 1, ['value_in_A1', 'value_in_B1']);
$addRow = function(\PHPExcel_Worksheet $worksheet, $column, $row, $values) {
iansltx / FastForwarder.php
Last active Aug 29, 2015
Calculate due dates, taking business days into account
View FastForwarder.php
class FastForwarder
protected $skipWhen = [];
protected $numDays = 0;
public static function createWithDays($num_days)
$ff = new static;
iansltx / EmailService.php
Last active Aug 29, 2015
Trait Injection
View EmailService.php
namespace BaseNamespace\Service;
// this should be an interface but I'm lazy
class EmailService
/* properties */
public function __construct(/* params */) {
iansltx /
Last active Aug 29, 2015
Local branch sharing

mDNS shows local machines

There are two network-related components of this utility: announce and pull. When you want to share a repo or branch with another user, you'll send an announcement to their host. That announcement will contain enough information to fetch the branch/repo from your system. When the targeted user receives the announcement, they can either ignore it or accept it. In the latter case, they may fetch the repo into its own new repo/branch or merge it with an existing local repo/branch via a temporary remote that lasts until they've finished pulling. If they want to share changes back with you, they announce the availability of a branch with the specified changes and you can accept/pull from them. Pushing from point to point (not counting the announcement) is not supported.

To allow for finer-grained ACLs, the announced remote is exposed via HTTP on a >1024 port with a set of credentials specific to a given announcement (which can contain exactly one repo or branch). The web server at this

iansltx /
Last active Aug 29, 2015
Messenger Mini Bookmarklet

To install this, create a bookmark and copy and paste the above verbatim into there. To use it, first go to the conversation you want to single out in, then navigate to the bookmarklet you created. The lefthand conversation list pane will vanish, and you'll be left with the IMs for your conversation in a window that has no minimum width (normally the conversation pane has a minimum width).

As fair warning, if Facebook updates the Messenger app then this hack may (probably will) stop working. This code is provided as-is and with no warranty whatsoever.

iansltx / rerender.js
Created Feb 3, 2015
Force element re-render on print
View rerender.js
(function() { // force re-render of element_name to get the styling right on-print
var beforePrint = function() {
var el = document.getElementById('element_name'); // e.g. an input inside a <p>...
var p = el.parentNode; // ...which will normally fail to style entirely on-print...
p.removeChild(el); // ...but if you wrap it in a <span> or the like, then remove and re-add the element...
p.appendChild(el); // ...the styles will recalculate and you'll get whatever style you were trying to apply!
if (window.matchMedia) {
window.matchMedia('print').addListener(function(mql) {
You can’t perform that action at this time.