Skip to content

Instantly share code, notes, and snippets.

View pete-rai's full-sized avatar

Pete Rai pete-rai

View GitHub Profile
@pete-rai
pete-rai / polly.js
Last active February 26, 2020 14:27
A wrapper around Amazon Polly to make text-to-speech in nodejs super simple.
'use strict'
/*
first install the following node modules:
npm install aws-sdk
npm install stream
npm install speaker
@pete-rai
pete-rai / pretty.js
Created February 7, 2018 20:56
A simple, concise, clean, no dependencies JSON pretty print output function
/*
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 / loglikelihood.php
Created February 7, 2018 21:00
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
<?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 / cleanse.php
Created February 7, 2018 21:09
A text cleansing function that is useful for preparing strings prior to lexical analysis.
<?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 / polly.js
Created February 18, 2018 22:36
A lean wrapper around Amazon Polly (which doesn't need the full AWS-SDK) making text-to-speech in nodejs super simple.
'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 / cache.php
Created January 3, 2019 17:29
A super simple PHP file based cache for any data type or structure
<?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 / logger.php
Created January 3, 2019 23:00
A simple PHP logger class with timestamps and trace support
<?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 / twitter.php
Created January 10, 2019 09:17
A simple PHP wrapper around the Twitter API with full authorization support
<?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 / timer.php
Created January 11, 2019 11:04
A simple PHP timer class with interim marker support
<?
/*
* 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 / cache.php
Created January 11, 2019 12:57
A simple PHP file based cache with support for cache expiry and storing any data type or structure
<?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