Skip to content

Instantly share code, notes, and snippets.

View rmccullagh's full-sized avatar

Ryan McCullagh rmccullagh

View GitHub Profile
<?php
$str = "Sending: 6011 1234 4321 1234:12/2016:543.21:John Doe
Received: Mon Apr 27 18:07:22 CDT 2015: Discover: 6011 1234 4321 1234 is valid: authorization code: 472080 for $543.21";
$a = preg_split("/\n/", $str);
array_shift($a);
$c = preg_match_all('/authorization\scode:\s[0-9]+/', $a[0], $matches);
$d = preg_split('/\n/', $matches[0][0]);
$e = explode(" ", $d[0]);
var_dump($e[2]);
@rmccullagh
rmccullagh / http.c
Created June 5, 2015 06:26
Hello HTTP server, that only implements GET|HEAD requests
/*
* Copyright (c) 2015 Ryan McCullagh <me@ryanmccullagh.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
/*
* memory allocation sub routine that DOES NOT fail
*/
void* tryAllocate()
{
void* buffer;
/*
* ascii whitespace:
* U+0009
* U+000A
* U+000C
* U+000D
* U+0020
*/
/*
* code point, four-to-six hex chars
static void __debug(const char* fname, const char* format, ...)
{
fprintf(stderr, "DEBUG: %s", fname);
va_list args;
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
}
#define debug(format, ...) __debug(__func__, format, __VA_ARGS__)
/**
*
* Copyright (c) 2015 Ryan McCullagh <me@ryanmccullagh.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
/*
* Copyright (c) 2015 Ryan McCullagh <me@ryanmccullagh.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
/*
* Copyright (c) 2015 Ryan McCullagh <me@ryanmccullagh.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@rmccullagh
rmccullagh / strfind.c
Created April 16, 2016 05:01
find the starting position of a string in a string
/*
* Copyright (c) 2016 Ryan McCullagh <me@ryanmccullagh.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
/*
* Copyright (c) 2016 Ryan McCullagh <me@ryanmccullagh.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of