Skip to content

Instantly share code, notes, and snippets.

View Kjaer's full-sized avatar
Code Janitor

Halil Kayer Kjaer

Code Janitor
View GitHub Profile
Kjaer / type_narrowing.ts
Last active July 17, 2023 12:22
Type narrowing with mapped types. This gist, iterate over nested union types and narrows the type definition for later filtering.
type Sitemap = {
pageIdentifier?: 'Page';
slug?: string | null;
seo?: { pageIdentifier: 'Seo'; noIndex?: boolean | null } | null;
| { pageIdentifier?: 'AppHomePage' }
| {
pageIdentifier: 'CategoryPage';
blockedInCountry?: boolean | null;
link?: string | null;
type Nested = {
foo: string;
bar: { baz: number; };
squick: { squeck: string; squawk: boolean; };
garble: { gobble: string; };
type Example = {
Kjaer /
Created November 11, 2022 12:17 — forked from troyfontaine/
Signing your Git Commits using GPG on MacOS

Methods of Signing with a GPG Key on MacOS

Last updated September 21, 2022

This Gist explains how to do this using gpg in a step-by-step fashion. Previously, was heavily mentioned, but I've only recently learned they were acquired by Akamai and no longer update their previous free products. Those mentions have been removed.

For using a GUI-based GIT tool such as Tower or Github Desktop, follow the steps here for signing your commits with GPG.

There has been a number of comments on this gist regarding some issues around the pinentry-program and M1 Macs. I've finally gotten a chance to try things out on an M1 and I've updated the documentation in to reflect my findings.

Kjaer /
Created July 31, 2022 15:30
Bash script knowledge with environment variables.
if [[ "${CYPRESS_ACCOUNT_ID:-}" ]]
export GRAPHQL_ACCOUNT_ID=$(grep GRAPHQL_ACCOUNT_ID .env.local | cut -d '=' -f2) && echo $GRAPHQL_ACCOUNT_ID
if [[ "${CYPRESS_API_TOKEN:-}" ]]
Kjaer / input.scss
Created July 11, 2022 10:12
Generated by
@use "sass:selector";
@use "sass:string";
@use "sass:map";
$alert-class: & !global;
color: green;
display: flex;
border: 1px solid yellow;
Kjaer / good_bad_ugly_code.js
Last active April 26, 2022 06:55
Good bad and ugly Code
// Bad
// Using another condition inside the ternary operator a.k.a nested ternary is bad.
products.filter(({ availableStock, quantity }) => availableStock !== undefined ? quantity <= availableStock : true)
// Ugly
// too many understanding requires, you need to be fully comprehend the double-pipe operator, then read the condition,
// yet code still feels uncertain taste in the mouth.
products.filter(({availableStock, quantity}) => availableStock === undefined || availableStock >= quantity
Kjaer / Concepts.svg
Last active April 9, 2023 00:52
Clean + MVVM Architecture
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Kjaer / proxy.js
Created February 7, 2020 12:46 — forked from beradrian/proxy.js
CORS proxy with node-http-proxy
/** If you want to use the local development environment with the dev backend,
* this will create a proxy so you won't run into CORS issues.
* It accepts the following command line parameters:
* - port the port where the proxy will listen
* - target the DEV backend target to contact.
* Example: If you set the port to 3000 and target to then
* your actual "resourceBaseUrl" in NiboSettings should be http://localhost:3000/api/v1
// Define the command line options
const optionDefinitions = [
Kjaer / iteration_of_collections.js
Created January 30, 2020 11:39
Performance tips for O(n²) on JavaScript iterations.
function charUnique(s) {
var r = {},
i, x;
for (i = s.length - 1; i > -1; i--) {
x = s[i];
if (r[x])
return false;
r[x] = true;
return true;
Kjaer / jest.config[2].js
Created October 15, 2019 15:22
"Setting up Jest and Enzyme for Typescript Next.js apps" post gists
module.exports = {
"testEnvironment": "node",
"roots": [
"preset": 'ts-jest',
"setupFilesAfterEnv": ["<rootDir>/tests/setupTests.ts"],
"transform": {
"^.+\\.tsx?$": "ts-jest"