Skip to content

Instantly share code, notes, and snippets.

View iansltx's full-sized avatar
💣
'); DROP TABLE statuses; --

Ian Littman iansltx

💣
'); DROP TABLE statuses; --
View GitHub Profile
<?php
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
iansltx / triples.py
Last active August 29, 2015 14:03
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 http://stackoverflow.com/a/8263898/2476827
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
iansltx / MyAction.php
Created July 18, 2014 23:42
On-construct ADR content type negotiation
<?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
iansltx / transform.php
Created August 12, 2014 04:25
Toggl CSV -> grouped by description and project + decimal hours QDPA
<?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
iansltx / phpexcel_convenience.php
Last active August 29, 2015 14:10
PHPExcel Convenience Functions
<?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
iansltx / FastForwarder.php
Last active August 29, 2015 14:15
Calculate due dates, taking business days into account
<?php
class FastForwarder
{
protected $skipWhen = [];
protected $numDays = 0;
public static function createWithDays($num_days)
{
$ff = new static;
@iansltx
iansltx / EmailService.php
Last active August 29, 2015 14:15
Trait Injection
<?php
namespace BaseNamespace\Service;
// this should be an interface but I'm lazy
class EmailService
{
/* properties */
public function __construct(/* params */) {
@iansltx
iansltx / local-branch-high-level.md
Last active August 29, 2015 14:21
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
iansltx / README.md
Last active August 29, 2015 14:23
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 messenger.com, 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
iansltx / rerender.js
Created February 3, 2015 08:23
Force element re-render on print
(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) {