Skip to content

Instantly share code, notes, and snippets.

View whymarrh's full-sized avatar

Whymarrh Whitby whymarrh

View GitHub Profile
@whymarrh
whymarrh / swap.c
Last active December 12, 2015 12:38
The XOR swap algoritm in C.
void swap(int *a, int *b);
int main(int argc, char **argv) {
int a = 1;
int b = 2;
swap(&a, &b);
return 0;
}
void swap(int *a, int *b) {
@whymarrh
whymarrh / com.whymarrh.apps.mediakeys.plist
Last active December 13, 2015 19:48
Sample p-list file for an OS X daemon.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.whymarrh.apps.mediakeys</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/the/executable/file</string>
</array>
@whymarrh
whymarrh / tends.c
Created March 16, 2013 22:59
A cool "tends to" operator in C (not actually).
#include <stdio.h>
#define as while
// as seen on Stack Overflow
// http://stackoverflow.com/q/1642028
int main(int argc, char **argv) {
int x = 42;
as (x --> 0) {
@whymarrh
whymarrh / inline.php
Last active December 16, 2015 23:49
In-lines CSS, JavaScript, and images.
#!/usr/bin/env php
<?php
define(SUCCESS, 0);
define(ERROR, 1);
if (count($argv) != 2) {
printf("usage: %s <filename>\n", basename($argv[0]));
exit(ERROR);
}
@whymarrh
whymarrh / BaseTestCase.php
Last active February 8, 2018 17:58
Assert HTML validity with PHPUnit.
<?php
use PHPUnit_Framework_Exception;
use PHPUnit_Framework_TestCase;
use SimpleXMLElement;
class BaseTestCase extends PHPUnit_Framework_TestCase
{
/**
* Show as much error information as possible
@whymarrh
whymarrh / test-pa11y.bash
Created August 3, 2013 21:36
Run nature/pa11y against an array of app routes.
#!/usr/bin/env bash
# servers
jeeves="localhost:7211"
alfred="localhost:7212"
abyss="/dev/null"
cd "public"
php -S "$jeeves" &> "$abyss" &
@whymarrh
whymarrh / dotcss.js
Last active December 25, 2015 12:59
Custom styles for everyone - $HOME/.css
DOMTokenList.prototype.add.apply(
window.document.documentElement.classList,
window.location.host.substring(0, window.location.host.lastIndexOf('.')).split('.')
);
@whymarrh
whymarrh / schema.sqlite3.sql
Last active December 26, 2015 17:29
Schema for ABA Lookup database. See issue #94.
-- PRAGMAs
PRAGMA foreign_keys = ON;
-- User
CREATE TABLE account(
id TEXT PRIMARY KEY,
user_id TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
password_reset_code TEXT NULL,
email TEXT UNIQUE NOT NULL,
@whymarrh
whymarrh / last.bash
Last active December 26, 2015 20:08
Print unique days on which I have used a machine.
#!/usr/bin/env bash
last | grep $(whoami) | tr -s ' ' | cut -d ' ' -f3 -f4 -f5 | uniq
@whymarrh
whymarrh / build.xml
Created November 16, 2013 03:36
Simple Ant build file.
<!--
Directory structure:
.
├── build.xml
├── libs
└── src
   └── foo
   └── bar