Skip to content

Instantly share code, notes, and snippets.

@gboudreau
gboudreau / jsonpp
Created December 5, 2011 14:38
JSON pretty-print from the command line
#!/usr/bin/php
<?php
echo json_format(file_get_contents('php://stdin')) . "\n";
// Pretty print some JSON
function json_format($json)
{
$tab = " ";
$new_json = "";
$indent_level = 0;
$in_string = false;
@gboudreau
gboudreau / smbln
Created January 3, 2012 22:23
smbln executable that allows the creation of symlinks on Samba shares mounted with the mfsymlinks option
#!/usr/bin/php
<?php
if ($argv[1] == '-s') {
$argv[1] = $argv[2];
$argv[2] = @$argv[3];
}
if (empty($argv[2])) {
$argv[2] = basename($argv[1]);
@gboudreau
gboudreau / recursive_include_parser-test.php
Created January 29, 2012 12:46
Testing recursive_include_parser function for Greyhole
<?php
file_put_contents('file1',
"this is file 1\r
include = file2
include = file3 # comment");
file_put_contents('file2', "this is file 2");
file_put_contents('file3',
@gboudreau
gboudreau / flickr-api-proxy.php
Created April 8, 2012 11:09
Flickr API proxy for Apple TV - Details: http://www.pommepause.com/blog/?p=530
<?php
$served_by = '';
if ($_GET['method'] == 'flickr.photos.search') {
if (strpos($_GET['text'], 'group:') === 0) {
$group_name = trim(substr($_GET['text'], 6));
$served_by = 'group.' . str_replace(' ', '_', $group_name) . '.';
$xml = file_get_contents('http://api.flickr.com/services/rest/?method=flickr.groups.search&api_key=' . $_GET['api_key'] . '&text=' . urlencode($group_name));
$xml = simplexml_load_string($xml);
$attr = $xml->groups->group->attributes();
@gboudreau
gboudreau / saved_plan.js
Created May 17, 2012 21:36
OTP display saved API response
// bougu@Netlift: this allows us to display the OTP UI with a predefined apiResponse (XML)
otp.planner.Forms.prototype.submitSuccessXML = function(response)
{
var responseXML;
if (window.DOMParser)
{
var parser=new DOMParser();
responseXML=parser.parseFromString(response,"text/xml");
}
else // Internet Explorer
@gboudreau
gboudreau / gh-du.php
Last active October 13, 2015 09:18
Greyhole Disk Usage Report Browser
<?php
# How to use: https://github.com/gboudreau/Greyhole/wiki/How-to-visualize-used-disk-space-in-your-storage-pool
header('Content-Type: text/html; charset=utf8');
setlocale(LC_CTYPE, "en_US.UTF-8");
if (!file_exists('/usr/share/greyhole/gh-disk-usage.log')) {
die("Error: /usr/share/greyhole/gh-disk-usage.log file not found.<br/>You need to run 'greyhole --fsck --disk-usage-report' to generate this file.");
}
@gboudreau
gboudreau / gist:5206966
Created March 20, 2013 18:03
Correctly handle errors with valid SSL certificates in cURL/PHP. Use this if you have problems connecting to https websites using PHP cURL extension. If the certificate is not signed by a CA listed in cURL's cacert.pem, you can use this technique to verify the certificate: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssl…
<?php
// [...]
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); // for security this should always be set to true.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // for security this should always be set to 2.
// Update cacert.pem (valid CA certificates list) from the cURL website once a month
$curl_cainfo = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cacert.pem';
$last_month = time()-30*24*60*60;

I'm writing in response to events that have recently come to light involving a sexual assault at a tech conference. Background information can be found [here][1], [here][2], and [here][3] as well as on twitter and google.


I've been watching this from the sidelines, and I've been wrestling with several questions that I can't seem to shake and that I really don't have answers to.

I wear many hats, both in the tech community and others. I'm a coder, a speaker, a user group organizer, a conference organizer, and even a boss. Each of those roles colors how I see this, but there's one role that is overpowering in my reaction.

See, I'm a Dad. A dad of two beautiful and innocent girls who are 3 and 2. They have their whole lives in front of them and so the questions I'm struggling with are:

@gboudreau
gboudreau / test_checksum.php
Last active February 29, 2016 15:24
Calculate the MD5 checksum of a file over and over, clearing the disk cache between each read, to try to identify read errors that are happening on a hard drive. Ref: https://www.pommepause.com/2016/02/the-case-of-the-dying-hard-drive-that-flipped-bits/
<?php
$file = '/mnt/hdd5/persistent-app-data/downloading/vvgoor1586DSFGKL.part10.rar';
while (TRUE) {
exec("sync ; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'");
$data1 = file_get_contents($file);
exec("sync ; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'");
$data2 = file_get_contents($file);
@gboudreau
gboudreau / fix_files.php
Last active February 29, 2016 15:24
Script to fix files copied from a dying hard drive that would sometimes read bytes as 0x10 less than what they are. Ref: https://www.pommepause.com/2016/02/the-case-of-the-dying-hard-drive-that-flipped-bits/
<?php
/**
* Use this script to check and fix a list of files that were copied, using rsync, from a bad (BAD!) hard drive to another hard drive (let's call that one the savior drive).
* Since the bad drive is so bad, the data that was copied off that drive might have been corrupted.
* So we'll find which of the listed files are wrong (different MD5 checksum on both drives), and fix them.
*
* Lucky for us, the dying drive is SO BAD that it never generates the same read errors, and when it does generate errors, the byte it reads is always exactly 0x10 (decimal 16) less than it should be.
* This very particular way of dying allows us to detect which of the two drive has the correct byte, and thus write a correct file on the savior drive.
* Hooray!