Skip to content

Instantly share code, notes, and snippets.

@RSully
RSully / DB.class.php
Last active September 10, 2019 08:21
Database class that extends PDO and adds easier to work with functionality (with prepared query caching)
<?php
/**
* Copyright 2012-2013 Ryan. All rights reserved.
* https://github.com/rsully
* https://gist.github.com/rsully/4162064
* You may use this code provided this message and the above copyright are kept in place.
**/
class DB extends PDO
{
protected $prepared = null;
<?php
class Generator {
protected $namespaces = [];
protected $outputDirectoriesPSR4 = [];
protected $aliasMapTypes = [];
protected $inputFiles = [];
/*
* Methods to setup the data we need to generate
@RSully
RSully / bourne.fish
Last active January 18, 2018 05:14
Source *sh environments from fish.
function set_bourne
set --local line $argv[1] # the line X=Y
set --local exp $argv[2] # 1/0: export the variable
set --local key (echo $line | perl -pe 's/^([A-Za-z0-9_]+)=(.*)/$1/g')
set --local dataraw (echo $line | perl -pe 's/^([A-Za-z0-9_]+)=(.*)/$2/g')
set --local data $dataraw
# echo "in set_bourne for $key with $exp"
# echo "old value: $$key"
@RSully
RSully / freadit.php
Created January 12, 2016 02:45
Keep trying to copy a file until success.
<?php
$path = '/Volumes/drive/path.dat';
$write_to = '/tmp/output.dat';
$fh_out = fopen($write_to, 'w+');
clearstatcache();
while (!file_exists($path)) {
sleep(1);
<?php
App::before(function($request)
{
// determine the subdomain of the current request
$server = explode('.', Request::server('HTTP_HOST'));
$sansSubdomain = implode('.', array_slice($server, 1));
// there are 3 parts to the domain (i.e. user.domain.com)
if (count($server) == 3)
@RSully
RSully / gol.php
Last active December 19, 2015 13:29
PHP implementation of Game Of Life
<?php
// Implementation
function iterate($original)
{
$board = $original;
for ($x = 0; $x < count($board); $x++) {
$row = $board[$x];
for ($y = 0; $y < count($row); $y++) {
$cell = $row[$y];
@RSully
RSully / sha.go
Last active December 19, 2015 11:09
My first Go program. Hash a file using a buffered reader
package main
/**
* Help from:
* http://stackoverflow.com/questions/1821811/how-to-read-write-from-to-file
* https://groups.google.com/forum/#!topic/golang-nuts/1mc64pj_S50
* http://pastebin.com/DgurHbpe
**/
import (
@RSully
RSully / call.php
Created April 24, 2013 14:24
This script can be used with something like `xdg` in order to add `sip:` handling to Chrome or Firefox using SFLphone. It takes a single argument, strips it to numerics and triggers a `dbus-send` to SFLphone's method to place a call. It uses the first account, which may or may not be what you want. `xdg-mime default sip-call-handler.desktop x-sc…
#!/usr/bin/php
<?php
// Requirements:
// sudo apt-get install php5-cli php-pear libyaml-dev
// sudo pecl install yaml
$file = $_SERVER['HOME'] . '/.config/sflphone/sflphoned.yml';
$acct_id = get_account_id($file);
$call_to = preg_replace('/[^0-9]/', '', $argv[1]);
@RSully
RSully / pcl2pdf.sh
Created April 19, 2013 00:37
Function to convert PCL to PDF using `pcl6`
pcl2pdf() {
input=$1
output=${2-$input.pdf}
pcl6 -o $output -sDEVICE=pdfwrite $input
}