Instantly share code, notes, and snippets.

Pete Rai pete-rai

View GitHub Profile
View cache.php
<?php
/*
* A simple PHP file based cache with support for cache expiry and storing any data type or structure
*
* Released with the karmaware tag - https://pete-rai.github.io/karmaware
*
* Website : http://www.rai.org.uk
* GitHub : https://github.com/pete-rai
* LinkedIn : https://uk.linkedin.com/in/raipete
View timer.php
<?
/*
* A simple PHP timer class with interim marker support
*
* Released with the karmaware tag - https://pete-rai.github.io/karmaware
*
* Website : http://www.rai.org.uk
* GitHub : https://github.com/pete-rai
* LinkedIn : https://uk.linkedin.com/in/raipete
View twitter.php
<?php
/*
* A simple PHP wrapper around the Twitter API with full authorization support
*
* Released with the karmaware tag - https://pete-rai.github.io/karmaware
*
* Website : http://www.rai.org.uk
* GitHub : https://github.com/pete-rai
* LinkedIn : https://uk.linkedin.com/in/raipete
View logger.php
<?php
/*
* A simple PHP logger class with timestamps and trace support
*
* Released with the karmaware tag - https://pete-rai.github.io/karmaware
*
* Website : http://www.rai.org.uk
* GitHub : https://github.com/pete-rai
* LinkedIn : https://uk.linkedin.com/in/raipete
View cache.php
<?php
/*
* A super simple PHP file based cache for any data type or structure
*
* Released with the karmaware tag - https://pete-rai.github.io/karmaware
*
* Website : http://www.rai.org.uk
* GitHub : https://github.com/pete-rai
* LinkedIn : https://uk.linkedin.com/in/raipete
View polly.js
'use strict'
/*
first install the following node modules:
npm install aws4
npm install https
npm install querystring
npm install speaker
npm install lame
View cleanse.php
<?php
function cleanse ($text)
{
$text = iconv ('UTF-8', 'ASCII//TRANSLIT//IGNORE', $text); // accented character to 'normal'
$text = preg_replace ('/[\r\n\s\t]+/xms', ' ' , $text); // normalise whitespace to one space
$text = preg_replace ('/[^\w\s]+/xms' , '' , $text); // remove all punctuation
return strtolower (trim ($text)); // lowercase and trimmed
}
View loglikelihood.php
<?php
// for more info see : http://ucrel.lancs.ac.uk/llwizard.html
// $n1 = total words in corpus 1 (usually the normative corpus)
// $n2 = total words in corpus 2
// $o1 = observed count for the word in corpus 1 (usually the normative corpus)
// $o2 = observed count for the word in corpus 2
function logLikelihood ($n1, $o1, $n2, $o2)
View pretty.js
/*
use the following in your css file
.json-key { color: red; }
.json-value { color: blue; }
.json-string { color: green; }
set your output like this:
View polly.js
'use strict'
/*
first install the following node modules:
npm install aws-sdk
npm install stream
npm install speaker