Skip to content

Instantly share code, notes, and snippets.

Pete Rai pete-rai

Block or report user

Report or block pete-rai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pete-rai
pete-rai / cache.php
Created Jan 11, 2019
A simple PHP file based cache with support for cache expiry and storing any data type or structure
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
@pete-rai
pete-rai / timer.php
Created Jan 11, 2019
A simple PHP timer class with interim marker support
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
@pete-rai
pete-rai / twitter.php
Created Jan 10, 2019
A simple PHP wrapper around the Twitter API with full authorization support
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
@pete-rai
pete-rai / logger.php
Created Jan 3, 2019
A simple PHP logger class with timestamps and trace support
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
@pete-rai
pete-rai / cache.php
Created Jan 3, 2019
A super simple PHP file based cache for any data type or structure
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
@pete-rai
pete-rai / polly.js
Created Feb 18, 2018
A lean wrapper around Amazon Polly (which doesn't need the full AWS-SDK) making text-to-speech in nodejs super simple.
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
@pete-rai
pete-rai / cleanse.php
Created Feb 7, 2018
A text cleansing function that is useful for preparing strings prior to lexical analysis.
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
}
@pete-rai
pete-rai / loglikelihood.php
Created Feb 7, 2018
Log-likelihood is a statistical technique that helps identify significant words in a given body of text when compared with a wider corpus. More information at: https://github.com/pete-rai/words-of-our-culture#log-likelihood
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)
@pete-rai
pete-rai / pretty.js
Created Feb 7, 2018
A simple, concise, clean, no dependencies JSON pretty print output function
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:
@pete-rai
pete-rai / polly.js
Last active Dec 2, 2018
A wrapper around Amazon Polly to make text-to-speech in nodejs super simple.
View polly.js
'use strict'
/*
first install the following node modules:
npm install aws-sdk
npm install stream
npm install speaker
You can’t perform that action at this time.