Skip to content

Instantly share code, notes, and snippets.

View jaabiri's full-sized avatar
🏠
Working from home

jaabiri salim jaabiri

🏠
Working from home
View GitHub Profile
@jaabiri
jaabiri / lambda.md
Created May 13, 2022 00:49 — forked from KyleAMathews/lambda.md
Using Kafka and a Samza-like node.js architecture

Disclaimer

I'm still very new to Kafka, eventsourcing, stream processing, etc. I'm in the middle of building my first production system with this stuff and am writing this at the request of a few folks on Twitter. So if you do have experience, please do me and anyone else reading this a favor by pointing out things I get wrong :)

Inspirations

@jaabiri
jaabiri / machine.js
Created February 17, 2022 15:50
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'hopauto',
initial: 'Information',
states: {
Information: {
on: {
SUIVANT: 'Livraison',
},
},
Livraison: {
@jaabiri
jaabiri / useStorage.js
Created July 2, 2021 01:48 — forked from mjackson/useStorage.js
A React hook for persisting state between page refreshes (also SSR compatible)
import { useEffect, useRef } from 'react';
function getItem(storage, key) {
const value = storage.getItem(key);
if (!value) return null;
try {
return JSON.parse(value);
} catch (error) {
@jaabiri
jaabiri / example.js
Created May 12, 2021 04:06 — forked from souporserious/example.js
File walker for Node
export async function getStaticProps(context) {
const pages = await walkFiles(path.resolve(process.cwd(), 'src/pages'));
return {
props: {
pages,
},
};
}
@jaabiri
jaabiri / GetOptimizationStatus.md
Created September 26, 2020 21:40 — forked from naugtur/GetOptimizationStatus.md
V8 %GetOptimizationStatus

%GetOptimizationStatus return a set of bitwise flags instead of a single value, to access the value, you need to take the binary representation of the returned value. Now, for example, if 65 is returned, the binary representation is the following:

(65).toString(2).padStart(12, '0');
// 000001000001

Each binary digit acts as a boolean with the following meaning:

@jaabiri
jaabiri / bash-cheatsheet.sh
Created August 25, 2020 04:44 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@jaabiri
jaabiri / deepDiffObj.js
Created July 29, 2020 11:01 — forked from tennox/deepDiffObj.js
Deep diff between two object, using lodash
import _ from 'lodash';
/**
* Deep diff between two objects - i.e. an object with the new value of new & changed fields.
* Removed fields will be set as undefined on the result.
* Only plain objects will be deeply compared (@see _.isPlainObject)
*
* Inspired by: https://gist.github.com/Yimiprod/7ee176597fef230d1451#gistcomment-2565071
* This fork: https://gist.github.com/TeNNoX/5125ab5770ba287012316dd62231b764/
*
const {useCallback, useEffect, useReducer, useRef} = require('react');
let effectCapture = null;
exports.useReducerWithEmitEffect = function(reducer, initialArg, init) {
let updateCounter = useRef(0);
let wrappedReducer = useCallback(function(oldWrappedState, action) {
effectCapture = [];
try {
let newState = reducer(oldWrappedState.state, action.action);
function useAbortController() {
const abortControllerRef = React.useRef()
const getAbortController = React.useCallback(() => {
if (!abortControllerRef.current) {
abortControllerRef.current = new AbortController()
}
return abortControllerRef.current
}, [])
React.useEffect(() => {
@jaabiri
jaabiri / stop-using-jwts.md
Created April 2, 2020 21:43 — forked from samsch/stop-using-jwts.md
Stop using JWTs

Stop using JWTs!

TLDR: JWTs should not be used for keeping your user logged in. They are not designed for this purpose, they are not secure, and there is a much better tool which is designed for it: regular cookie sessions.

If you've got a bit of time to watch a presentation on it, I highly recommend this talk: https://www.youtube.com/watch?v=pYeekwv3vC4 (Note that other topics are largely skimmed over, such as CSRF protection. You should learn about other topics from other sources. Also note that "valid" usecases for JWTs at the end of the video can also be easily handled by other, better, and more secure tools. Specifically, PASETO.)

A related topic: Don't use localStorage (or sessionStorage) for authentication credentials, including JWT tokens: https://www.rdegges.com/2018/please-stop-using-local-storage/

The reason to avoid JWTs comes down to a couple different points:

  • The JWT specification is specifically designed only for very short-live tokens (~5 minute or less). Sessions