Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jakefolio on github.
  • I am jakefolio (https://keybase.io/jakefolio) on keybase.
  • I have a public key ASCOleJr1TygYSfVcj60YjwYUTIcfWTzQlwy9VoFjgaKPwo

To claim this, I am signing this object:

@jakefolio
jakefolio / durations.php
Created October 17, 2016 19:27
Add duration strings into DateInterval
<?php
$durations = [
'2:01:05',
'2:35:25',
'1:45:01',
];
function getDateIntervalFromString($duration) {
$i = 0;
@jakefolio
jakefolio / Form.rb
Created July 6, 2016 14:48
Custom validation
validation :campaign_date_range, if: :default do
# start and end date have been coerced to DateTime
required(:starts_at, &:valid_start_date?)
required(:ends_at, &:valid_end_date?)
def valid_start_date?(value)
value > form.ends_at
end
def valid_end_date?(value)
@jakefolio
jakefolio / Collection.php
Created May 27, 2016 16:01
Low memory usage collection
<?php
namespace jakefolio;
class Collection implements \ArrayAccess, \Countable, \IteratorAggregate
{
protected $items;
public function __construct($items = [])
{
var fs = require('fs');
var stream = fs.createReadStream('./test/fixtures/current');
var currentData = '';
stream.on('error', function (err) {
throw err;
});
stream.on('data', function (data) {
currentData += data;
});
<?php
class AncientFileFilter extends \FilterIterator {
protected $DaysOld = 7;
public function __construct($dir,$days=null) {
// is the specified directory valid?
if(!is_string($dir) || !is_dir($dir) || !is_readable($dir))
<?php
class AncientFileFilter extends \FilterIterator {
protected $DaysOld = 7;
public function __construct($dir,$days=null) {
// is the specified directory valid?
if(!is_string($dir) || !is_dir($dir) || !is_readable($dir))
I have my model here:
// transactionmodel.js
function TransactionModel() {
var pg = require('pg');
var connectionString = "pg://chartjes:******@localhost:5432/ibl_stats";
this.client = new pg.Client(connectionString);
this.client.connect();
this.getCurrent = function() {
@jakefolio
jakefolio / index.php
Created February 16, 2012 21:38
Only load the routes you want based off of URI params
<?php
// Stupid dirty example of how to load only the routes you want.
$app->hook('slim.before.router', function() use ($app) {
$uri = $app->request()->getResourceUri();
$params = explode('/', substr($uri, 1, strlen($uri)));
if (file_exists(APP_ROOT . '/app/routes/' . $params[0] . '.php'))
include APP_ROOT . '/app/routes/' . $params[0] . '.php';
});
Our bodies are just like a legacy code base, we are old in internet years! Just like most legacy
code bases rewriting isn't an option, so you have to slowly refactor. We, developers, spend the majority
of our time sitting and possibly with terrible posture. Our schedules lead to poor eating choices and
physical exercise falls to the wayside. I will discuss the way I refactored my physical body and the incremental
changes that has lead to a more enjoyable life. You will leave with a plan to improve your overall health.