Skip to content

Instantly share code, notes, and snippets.

@mgdm
mgdm / jsonprint
Created April 6, 2011 16:54
Pretty-print JSON from any URL PHP's file_get_contents can reach
#!/usr/bin/php
<?php
function usage() {
echo "Usage: " . $_SERVER['argv'][0] . " [-v] URL\n";
echo "\nPretty-prints JSON output from a URL.";
echo "\n\t-v\tDecode JSON and use var_dump to display result\n";
}
@mgdm
mgdm / karate.php
Created December 17, 2011 19:11
RSVG with scaling
<?php
$width = $height = 1000;
if (isset($_GET['width'])) {
$width = (int) $_GET['width'];
}
if (isset($_GET['height'])) {
$height = (int) $_GET['height'];
<?php
$str = "This
is
a
multi
line
string";
var_dump($str);
@mgdm
mgdm / mesh_pattern.c
Created July 22, 2012 11:59
Mesh pattern demo
/* Mesh pattern demo - requires Cairo 1.12
* Compile with:
* gcc -I/usr/include/cairo -o mesh_pattern mesh_pattern.c -lcairo
* (or similar)
*
* Running will create 'mesh.png' in the current directory
* Michael Maclean <[email protected]>
*/
#include <cairo.h>
@mgdm
mgdm / listdir.c
Created July 23, 2012 13:51
List contents of extremely large directories
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#define handle_error(msg) \
@mgdm
mgdm / addrs.c
Created October 18, 2012 21:47
Address parser
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LCD_ALIAS_REAL "DS18B20.28b8c81d300e5.Temp,DS18B20.2816401d3005f.Temp,DS18B20.28ac871d300e4.Temp"
#define LCD_ALIAS_ALIAS "Front_air_intake,Bottom_hose_temp,Top_hose_temp"
int main() {
char **devices;
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
rebuilding aclocal.m4
rebuilding configure
configure.in:150: warning: LTOPTIONS_VERSION is m4_require'd but not m4_defun'd
aclocal.m4:2955: LT_INIT is expanded from...
aclocal.m4:2993: AC_PROG_LIBTOOL is expanded from...
configure.in:150: the top level
@mgdm
mgdm / pixels.php
Created April 8, 2013 14:05
'Pixellate' a graphic based on mesh gradients
<?php
define('BOX_WIDTH', 45);
define('BOX_MARGIN', 5);
$image = imagecreatefromjpeg('callanish.jpg');
$width = imagesx($image);
$height = imagesy($image);
$s = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$c = new CairoContext($s);
@mgdm
mgdm / .zshrc
Last active December 17, 2015 12:18
zshrc for Antigen setup
ZSHA_BASE=$HOME/.zsh-antigen
source $ZSHA_BASE/antigen/antigen.zsh
antigen-use oh-my-zsh
antigen-bundle git
if [ "$OSTYPE"="darwin11.0" ]; then
antigen-bundle osx
fi
@mgdm
mgdm / notify
Last active December 20, 2015 00:09
Fire up terminal-notifier without requiring a Ruby wrapper to do so.
#!/bin/sh
# Fire up terminal-notifier.app without needing a Ruby wrapper
# Stolen from the `mvim` script distributed with MacVim.
#
# Credits for the MacVim version are:
# Based on a script by Wout Mertens and suggestions from Laurent Bihanic. This
# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
# Weber and Bjorn Winckler, Aug 13 2007).
#