Skip to content

Instantly share code, notes, and snippets.

View ciarand's full-sized avatar

Ciaran Downey ciarand

View GitHub Profile
@ciarand
ciarand / index.php
Last active August 29, 2015 13:56
Export / import PHP request details for reproducible debugging
<?php // index.php
// bulletproof debug mode
define("DEBUG_MODE", rand(1, 2) === 1);
if (isset($_GET["trigger"]) && DEBUG_MODE) {
file_put_contents("request.dat", serialize(get_defined_vars()));
}
// go through normal stuff, start the app, etc.
@ciarand
ciarand / testing-proc-state.pl
Created June 11, 2014 17:43
A quick demonstration of testing a programming assignment with Perl
#!/usr/bin/env perl -w
use strict;
use warnings;
use Test::Simple tests => 7;
sub check_output_contains {
my $output = shift;
my $wanted = shift;
@ciarand
ciarand / pointers.c
Created June 17, 2014 23:12
trouble with pointers dot c
#include <stdio.h>
#include <stdlib.h>
#define LINE_LENGTH 1024
int get_line_with_prefix_from_file(const char* prefix, FILE* file, char* result_buf) {
char line_buf[LINE_LENGTH];
int matches = 0;
while (fgets(line_buf, LINE_LENGTH, file)) {
@ciarand
ciarand / getting_started_with_hugo.bash
Created June 22, 2014 15:31
getting_started_with_hugo.bash
wget https://github.com/spf13/hugo/releases/download/v0.11/hugo_0.11_linux_386.tar.gz
tar xvzf hugo_0.11_linux_386.tar.gz
mv hugo_0.11_linux_386/hugo_0.11_linux_386 hugo
chmod +x ./hugo
./hugo new site blah
echo "your new site is in 'blah'"
@ciarand
ciarand / SnapshotCommand.php
Created June 23, 2014 03:18
A simple Artisan command to echo the response from a given route
<?php
use Illuminate\Console\Command;
use Illuminate\Foundation\Testing\Client;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class SnapshotCommand extends Command
{
/**
@ciarand
ciarand / lol.bash
Last active August 29, 2015 14:03
How do I even indent this correctly
# move all the front-end assets into a public dir
find . -type f \( \
-name "*.css" -o \
-name "*.html" -o \
-name "*.js" -o \
-name "robots.txt" -o \
-name "humans.txt" -o \
-name "favicon.ico" -o \
-name ".htaccess" \) |
while read file
@ciarand
ciarand / bootstrap_coreos_on_linode_debian.sh
Created July 25, 2014 23:22
Bootstrap a Debian 7.5 Linode server w/ CoreOS
# sources:
# - http://stackoverflow.com/questions/24585419/
# - https://coreos.com/docs/running-coreos/bare-metal/installing-to-disk/
# - https://www.linode.com/docs/platform/custom-kernels-distros/run-a-distributionsupplied-kernel-with-pvgrub
set -e -o pipefail
apt-get update -y
apt-get upgrade -y --show-upgraded
mkdir /boot/grub
@ciarand
ciarand / result.php
Last active August 29, 2015 14:04
Playing around with creating an intuitive API for Result-type objects (i.e. Failure / Success wrappers) and their interactions w/ Exceptions
<?php
abstract class Result
{
public static function fromValue($value, $reject = null)
{
return ($value !== $reject) ? new Success($value) : new Failure;
}
public static function failOnException($callback)
@ciarand
ciarand / index.html
Created September 1, 2014 21:47
experiments with websockets and app.net
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>socketdotnet</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"