Skip to content

Instantly share code, notes, and snippets.

@Harrisonkamau
Harrisonkamau / myFile.js
Created December 16, 2020 21:29
Check if Object has Key and Object deep cloning in JavaScript
const hasKey = (obj, key) => obj[key] === undefined;
const deepCloneObj = (obj) => JSON.parse(JSON.stringify(obj));
@Harrisonkamau
Harrisonkamau / dateString.js
Created November 30, 2020 09:28
Only render HH:MM AM/PM timestamp using JS
const date = new Date();
date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); // E.g. 12:30 PM
@Harrisonkamau
Harrisonkamau / removeItem.js
Last active November 29, 2020 12:40
Remove a specific item from an Array in JavaScript. All instances of that item will be removed
// Adding to the prototype so it can be used like a normal array method
Array.prototype.removeItem = function removeItem(item) {
const formattedItem = typeof item === 'string' ? item.trim().toLowerCase() : item;
const formattedItems = this.map((currentItem) => {
if (typeof currentItem === 'string') {
return currentItem.toLowerCase();
};
return currentItem;
});
@Harrisonkamau
Harrisonkamau / machine.js
Last active April 30, 2020 17:09
Generated by XState Viz: https://xstate.js.org/viz
const paymentMachine = Machine({
id: 'payment',
initial: 'plan',
states: {
plan: {
initial: '$10',
states: {
'$10': { on: { SWITCH_PLAN: '$20' } },
'$20': { on: { SWITCH_PLAN: '$10' } },
hist: { type: 'history' },
@Harrisonkamau
Harrisonkamau / secretsRotation.js
Last active October 31, 2019 08:47
AWS Secrets Rotation using Node.js (aws-sdk)
// Ensure you have installed these two packages
const AWS = require('aws-sdk');
const config = require('config');
// this assumes that you have a config folder at the root of the project
// check more about node-config here:
// https://github.com/lorenwest/node-config
// if you're not using `config`, then the values from the .env file as shown below
// check sample config files contained in the config folder
@Harrisonkamau
Harrisonkamau / deepEqual.js
Created September 20, 2019 16:04
Testing for deep equivalence between two JavaScript arrays
// let's try the old way
const arr1 = [1,2,3];
const arr2 = [1,2,3];
console.log(arr1 === arr2); // returns false
// Hello JSON.stringify()!
console.log(JSON.stringify(arr1) === JSON.stringify(arr2)); // true
@Harrisonkamau
Harrisonkamau / index.html
Created September 14, 2016 14:57
These are my files. I would like to receive an sms when i enter my phone number on the Send link form. Currently, the system works when I run the code on the terminal.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>OCharge</title>
<link href="https://fonts.googleapis.com/css?family=Quicksand:300,400,700" rel="stylesheet">
<!-- Bootstrap -->

SCSS Mended Heart tribute Pray for Orlando

Tribute for all of the lives loss in the Orlando attack @ Pulse nightclub. Mended heart using sass

A Pen by Harrison on CodePen.

License.