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
<?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 Aug 29, 2015
Get a list of all primitive Pythagorean triples with hypotenuse <= Nmax, one per line
View triples.py
# 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 Jul 18, 2014
On-construct ADR content type negotiation
View MyAction.php
<?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 Aug 12, 2014
Toggl CSV -> grouped by description and project + decimal hours QDPA
View transform.php
<?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 / _safari-iframe-cookie-workaround.md
Last active Jan 21, 2020
Safari iframe cookie workaround
View _safari-iframe-cookie-workaround.md
@iansltx
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
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) {
@iansltx
iansltx / FastForwarder.php
Last active Aug 29, 2015
Calculate due dates, taking business days into account
View FastForwarder.php
<?php
class FastForwarder
{
protected $skipWhen = [];
protected $numDays = 0;
public static function createWithDays($num_days)
{
$ff = new static;
@iansltx
iansltx / EmailService.php
Last active Aug 29, 2015
Trait Injection
View EmailService.php
<?php
namespace BaseNamespace\Service;
// this should be an interface but I'm lazy
class EmailService
{
/* properties */
public function __construct(/* params */) {
@iansltx
iansltx / MultiPartFromStrings.php
Created May 2, 2015
Multipart file uploads in PHP from strings
View MultiPartFromStrings.php
<?php
/**
* PHP's curl extension won't let you pass in strings as multipart file upload bodies; you
* have to direct it at an existing file (either with deprecated @ syntax or the CURLFile
* type). You can use php://temp to get around this for one file, but if you want to upload
* multiple files then you've got a bit more work.
*
* This function manually constructs the multipart request body from strings and injects it
* into the supplied curl handle, with no need to touch the file system.
You can’t perform that action at this time.