Skip to content

Instantly share code, notes, and snippets.

Chris Thompson cjthompson

  • Osiris Development
  • Colorado, USA
Block or report user

Report or block cjthompson

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:80cce78894edcbc04b8b
(*
the 'args' dictionary contains following variables:
URL => my-http://myhost.domain.com:8080/mysite/a.html?search=blah#myanchor
URL_SCHEME => my-http
URL_HOST => myhost.domain.com
URL_PORT => 8080
URL_PATH => /mysite/a.html
URL_QUERY => ?search=blah
URL_FRAGMENT => #myanchor
URL_VALUE => everything that comes after the 'scheme:'
@cjthompson
cjthompson / strace55.txt
Created Feb 10, 2016
Node 5.5.0 with /etc/nsswitch.conf permissions set to 600
View strace55.txt
execve("./node", ["./node"], [/* 32 vars */]) = 0
brk(0) = 0x288c000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd8ca824000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=26694, ...}) = 0
mmap(NULL, 26694, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd8ca81d000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
@cjthompson
cjthompson / strace.txt
Created Feb 10, 2016
Node 5.6.0 with /etc/nsswitch.conf permissions set to 644
View strace.txt
execve("./node56", ["./node56"], [/* 17 vars */]) = 0
brk(0) = 0x340d000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f64b6c1b000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=30969, ...}) = 0
mmap(NULL, 30969, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f64b6c13000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
@cjthompson
cjthompson / node56-nsswitch.conf
Created Feb 10, 2016
Node 5.6.0 crash with nsswitch.conf permissions set to 600
View node56-nsswitch.conf
# /etc/nsswitch.conf is set to 600
strace ./node
execve("./node", ["./node"], [/* 32 vars */]) = 0
brk(0) = 0x2f42000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f01cb5de000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=26694, ...}) = 0
@cjthompson
cjthompson / randomString.js
Created Jun 16, 2015
JavaScript: random string
View randomString.js
var _ = require('lodash');
var randomString = function (length) {
return _(length).range().map(_.partial(_.random, 33, 126, false)).map(_.ary(String.fromCharCode)).join('');
};
@cjthompson
cjthompson / readableNumber.js
Created Feb 21, 2014
Convert a number into a human readable number with 3 significant digits followed by 'K' (thousand), 'M' (million), or 'B' (billion)
View readableNumber.js
function readableNumber(num) {
var s = ['', 'K', 'M', 'B'];
var e = Math.floor(Math.log(num) / Math.log(1000));
return (num / Math.pow(1000, e)).toPrecision(3) + s[e];
}
@cjthompson
cjthompson / RobustPDO.php
Created Feb 3, 2014
Extended PDO class that detects dropped connections and reconnects
View RobustPDO.php
<?php
class RobustPDO extends PDO
{
/** Call setAttribute to set the session wait_timeout value */
const ATTR_MYSQL_TIMEOUT = 100;
/** @var array */
protected $config = [];
/** @var bool For lazy connection tracking */
@cjthompson
cjthompson / arrayDifference.php
Last active Jan 16, 2019
PHP: Compare two arrays and find the differences between them. Supports items that are arrays by serializing them for comparison. Returns an array of insertions (only in the second array) and deletions (only in the first array).
View arrayDifference.php
<?php
/**
* Compare two arrays and return a list of items only in array1 (deletions) and only in array2 (insertions)
*
* @param array $array1 The 'original' array, for comparison. Items that exist here only are considered to be deleted (deletions).
* @param array $array2 The 'new' array. Items that exist here only are considered to be new items (insertions).
* @param array $keysToCompare A list of array key names that should be used for comparison of arrays (ignore all other keys)
* @return array[] array with keys 'insertions' and 'deletions'
*/
public static function arrayDifference(array $array1, array $array2, array $keysToCompare = null) {
View MySQL Dump Tables
#!/bin/bash
USER="user"
PASSWORD="password"
HOST="localhost"
MYSQL_OPTS="--compact --single-transaction --skip-opt --quick --no-create-info --skip-triggers"
if [ "$1" == "" ]; then
echo "Usage: $0 database-name [output-dir]"
exit 1
fi
@cjthompson
cjthompson / DeleteDuplicates.sql
Created Mar 20, 2013
Find duplicate records in a MySQL database, save the first row of a set of duplicates, and delete the rest.
View DeleteDuplicates.sql
-- Assume `Table` has 4 columns: id, col1, col2, col3
CREATE TABLE `dups` (
`id` int(10) unsigned DEFAULT NULL,
`hash` varbinary(32) DEFAULT NULL,
KEY `id` (`id`),
KEY `hash` (`hash`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO dups SELECT MIN(id) AS id, MD5(CONCAT(col1, col2, col3)) AS hash FROM `Table` GROUP BY col1, col2, col3 HAVING COUNT(*) > 1;
You can’t perform that action at this time.