Skip to content

Instantly share code, notes, and snippets.

View chardcastle's full-sized avatar

Chris Hardcastle chardcastle

  • London (England)
View GitHub Profile
@chardcastle
chardcastle / build-couchdb-documents
Created February 20, 2014 10:25
Stash data away into couchdb (build script)
<?php
// Get a unique ID for document
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:5984/_uuids');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Accept: */*'
));
@chardcastle
chardcastle / gist:9229799
Created February 26, 2014 13:54
Date subtraction PHP
<?php
$date = new DateTime('Europe/London');
$date->sub(DateInterval::createFromDateString('12 days'));
echo $date->format('d-m-y');
@chardcastle
chardcastle / gist:9eff528a8752a05abfac
Created October 15, 2014 09:33
DateTime calculator
<?php
var_dump(DateTime::createFromFormat('d-m-Y','01-01-2013')->add(date_interval_create_from_date_string('2 years'))->format('d-m-Y'));
?>
@chardcastle
chardcastle / gist:2d610f6208f893d9b52d
Created October 19, 2014 21:51
clear all blank lines from vim
:g/^$/d
# @see http://stackoverflow.com/questions/706076/vim-delete-blank-lines
@chardcastle
chardcastle / gist:f3b5eedef975de8f28a3
Created October 20, 2014 09:55
Traverse array in batch YII Framework
<?php
/**
* Prototype method for traversing large records in batches
* using the YII framework.
*
* Completed stepper method for restoration rollback solution.
*
* @todo Include this in main restoartion rollback solution
* @return [type] [description]
*/
@chardcastle
chardcastle / gist:6fb037559e3cc90e0028
Last active August 29, 2015 14:09
Simple PHP checksum (legacy fix)
<?php
// Interesting legacy fix
//
// This works by replacing a collection of 10 blank spaces with a random character.
// However the \e modifier is deprecaited now, it needed replacing as it's hard to
// underststand without some notes.
//
// This line appears to come from http://php.net/manual/en/function.rand.php#86465
//
// $f->checksum = preg_replace('/([ ])/e', 'chr(rand(97,122))', ' ');
@chardcastle
chardcastle / Kohana cron.php
Created May 17, 2010 22:44
My cron file for kohana 2.3.4
<?php
/**
* Created by Chris Hardcastle to run cron jobs
* Based on the default kohana 2.3.4 index.php
* Note the required #! stated above
* CRON TAB USAGE (To run twice a day)
0 0,12 * * * /usr/bin/php [root][site]/cron.php --controller --method
*
* Use the shebang --> #!/usr/bin/php (should you need it, thanks @spolster)
*/
@chardcastle
chardcastle / toggle-selected-link-in-pagination.js
Created May 18, 2010 22:57
Toggle selected link in pagination - JQuery
@chardcastle
chardcastle / jQuery image pre-load
Created July 5, 2010 22:26
Image preloading in JQuery
/*
* Written by Chris Hardcastle
* Pre-load an image using jQuery
* Example HTML layout
<div id="globalInner">
<div id="loading"><!-- css loading gif --></div>
<div id="stage"></div>
</div>
*/
/*
@chardcastle
chardcastle / move-files-into-folder.bash
Created July 31, 2010 20:07
Move files on condition - linux line command
find ./ -name "*.css" -print0 | xargs -0 -I xxx mv xxx css/