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 / find-image-in-image.js
Created January 13, 2021 17:29
Find an image within another image using nodejs, using the node sharp library (https://www.npmjs.com/package/sharp). Note: This does not handle PNG transparencies - I may add that next - let me know if you need it.
const sharp = require('sharp');
async function findImageWithinImage(outer, inner, max = 1) // max is the maximum occurences to find
{
let file_o = sharp(outer);
let file_i = sharp(inner);
let buff_o = await file_o.raw().toBuffer();
let buff_i = await file_i.raw().toBuffer();
let meta_o = await file_o.metadata();
let meta_i = await file_i.metadata();
@pete-rai
pete-rai / async-method-chaining.js
Created January 13, 2021 11:45
Method chaining is useful way to construct readable software. It is a process where each method returns an object, allowing the calls to be chained together in a single statement without requiring variables to store the intermediate results. However, how can we achieve this in the face of JavaScript’s asynchronous function? Here is a simple solu…
/*
Method chaining is useful way to construct readable software. It is a process
where each method returns an object, allowing the calls to be chained together
in a single statement without requiring variables to store the intermediate
results. However, how can we achieve this in the face of JavaScript’s
asynchronous function? Here is a simple solution for this tricky issue.
*/
@pete-rai
pete-rai / 3d-card-wheel.html
Created January 13, 2021 10:42
A 3D wheel of cards where cards can be added and removed and the wheel spun to place any card at the front. This is a pure CSS solution based on transforms. Modify the card template to make whatever you want to appear inside each card. See it in action here: https://codepen.io/pete-rai/full/dypgwLw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>3D Card Wheel</title>
<style>
html,
body {
@pete-rai
pete-rai / sequencer.js
Created January 12, 2021 15:15
An example of using Javascript Promises to ensure that a set of asyncronous steps are always performed in the specified order and strictly one after another.
/*
An example of using Javascript Promises to ensure that a set of asyncronous
steps are always performed in the specified order and strictly one after
another.
*/
// --- some async function that takes some time to complete
@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
@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 / 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 / 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 / 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 / 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