Skip to content

Instantly share code, notes, and snippets.

View karimsa's full-sized avatar

Karim Alibhai karimsa

View GitHub Profile
@karimsa
karimsa / debugComponentChanges.ts
Last active December 21, 2023 21:28
debug react component renders
/* eslint-disable n/no-process-env */
import { useCallback, useEffect, useRef } from "react";
function useChangedValues(values: Record<string, unknown>) {
const valueStore = useRef(new Map()).current;
const changedKeys: string[] = [];
for (const [key, val] of Object.entries(values)) {
if (valueStore.get(key) !== val) {
@karimsa
karimsa / uninstall.js
Last active April 28, 2021 04:38
Reset service workers
self.addEventListener('install', function(e) {
self.skipWaiting();
});
self.addEventListener('activate', function(e) {
self.registration.unregister()
.then(function() {
return self.clients.matchAll();
})
.then(function(clients) {
@karimsa
karimsa / ci-env.sh
Last active March 23, 2019 01:00
CI-agnostic Env Variables
#!/bin/bash -e
## Maps env variables from different CIs to common names. Useful for changing between CIs.
##
## eval "$(curl -sSL https://gist.githubusercontent.com/karimsa/737c7220348bfa0a3d4e4689bcc34491/raw/ci-env.sh)"
##
## Licensed under MIT license.
## Copyright (C) 2019-present Karim Alibhai. All rights reserved.
if test "$CI" != "true"; then
@karimsa
karimsa / docker-deploy.sh
Created January 14, 2019 20:09
Deploy private docker image
#!/bin/sh -ex
# docker-deploy.sh
# Deploys image from Travis to ECR.
#
# Copyright (C) 2017-present Karim Alibhai. All rights reserved.
export PROJECT="$(cat .travis.yml | grep 'repo\:' | head -n 1 | cut -d\: -f2 | cut -d/ -f2 | sed 's/^dyn-//')"
if test -z "$TRAVIS_PULL_REQUEST" || test "$TRAVIS_PULL_REQUEST" != "false"; then
@karimsa
karimsa / to-json.js
Created October 1, 2018 16:10
Serialize an ES2015 Map object to a JSON object
/**
* Serialize map to object. Goal is to be able to use 'Map' over object when performing
* large algorithms over a hash map - but then serializing it to an object for sending
* over a wire.
*/
Map.prototype.toJSON = function() {
const o = Object.create(null)
for (const k of this.keys()) {
if (typeof k !== 'string' && typeof k !== 'number') {
@karimsa
karimsa / merge.sh
Last active September 6, 2018 16:09
Create a combined branch for deploying multiple branches to a single test environment
#!/bin/sh -ex
## merge.sh
##
## The purpose of this script is to cover the merging of a given list of branches so that
## multiple branches can be deployed to the same test environment in order to test PRs on
## a staging environment before merging the PR.
##
## Licensed under MIT license.
## Copyright (C) Foko Inc. All rights reserved.
@karimsa
karimsa / about.md
Last active November 14, 2019 00:38
My Talks

About the Speaker (Me)

I'm a Senior Bug Creator which basically means that I get paid to sit behind a desk and create lots of bugs that we sometimes call "features". I've been writing JavaScript for about 10 years now & have loved every second of it. It always amazes me how much extensibility and dynamic behavior JS brings to development.

I'm also an advocate for better DX & love working on tools and processes that can help augment a developer's life. Part of this journey has been learning that building more stable systems is more a product of treating error handling as an art than to do with removing bugs. I've been fortuanate enough to have the opportunity to speak at a few events as well as teach web development before. It's my favourite part of the development life & I love opportunities to share my experiences while learning about experiences from the community.

  • If you want to check out some of my talks or projects, you can visit: https://alibhai.co
  • I occasionally write blo
@karimsa
karimsa / commit_format_examples.txt
Created March 14, 2018 03:32 — forked from mutewinter/commit_format_examples.txt
Examples of my commit format.
chore: add Oyster build script
docs: explain hat wobble
feat: add beta sequence
fix: remove broken confirmation message
refactor: share logic between 4d3d3d3 and flarhgunnstow
style: convert tabs to spaces
test: ensure Tayne retains clothing
@karimsa
karimsa / getReceipt.js
Created February 2, 2017 18:33
Algorithm to read basic receipts using OCR response from MS cognitive services. Built for McHacks 2017.
/**
* getReceipt.js - Split
* Logic to convert a JSON response from
* the MS Cognitive Services OCR API into
* proper receiptable data.
*
* Licensed under MIT license.
* Copyright (C) 2017 Karim Alibhai.
*/
/**
* Script to download all comics from xkcd.
*/
'use strict';
const fs = require('fs')
const cheerio = require('cheerio')
const request = require('request')