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
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;
content?:
| { pageIdentifier?: 'AppHomePage' }
| {
pageIdentifier: 'CategoryPage';
blockedInCountry?: boolean | null;
link?: string | null;
// https://stackoverflow.com/a/72366029/5018572
type Nested = {
foo: string;
bar: { baz: number; };
squick: { squeck: string; squawk: boolean; };
garble: { gobble: string; };
};
type Example = {
@Kjaer
Kjaer / 1-setup.md
Created November 11, 2022 12:17 — forked from troyfontaine/1-setup.md
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, krypt.co 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 2-using-gpg.md to reflect my findings.

@Kjaer
Kjaer / Graphql_env.sh
Created July 31, 2022 15:30
Bash script knowledge with environment variables.
if [[ "${CYPRESS_ACCOUNT_ID:-}" ]]
then
export GRAPHQL_ACCOUNT_ID=$CYPRESS_ACCOUNT_ID && echo $GRAPHQL_ACCOUNT_ID
else
export GRAPHQL_ACCOUNT_ID=$(grep GRAPHQL_ACCOUNT_ID .env.local | cut -d '=' -f2) && echo $GRAPHQL_ACCOUNT_ID
fi
if [[ "${CYPRESS_API_TOKEN:-}" ]]
then
export GRAPHQL_AUTHORIZATION=$CYPRESS_API_TOKEN && echo $GRAPHQL_AUTHORIZATION
@Kjaer
Kjaer / input.scss
Created July 11, 2022 10:12
Generated by SassMeister.com.
@use "sass:selector";
@use "sass:string";
@use "sass:map";
.alert{
$alert-class: & !global;
color: green;
display: flex;
border: 1px solid yellow;
}
@Kjaer
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
Kjaer / Concepts.svg
Last active April 9, 2023 00:52
Clean + MVVM Architecture
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kjaer
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 https://dev.nibo.ai then
* your actual "resourceBaseUrl" in NiboSettings should be http://localhost:3000/api/v1
*/
// Define the command line options
const optionDefinitions = [
@Kjaer
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
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": [
"<rootDir>/components"
],
"preset": 'ts-jest',
"setupFilesAfterEnv": ["<rootDir>/tests/setupTests.ts"],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},