Skip to content

Instantly share code, notes, and snippets.

Avatar
👷‍♂️
Code Janitor

Halil Kayer Kjaer

👷‍♂️
Code Janitor
View GitHub Profile
@Kjaer
Kjaer / Graphql_env.sh
Created Jul 31, 2022
Bash script knowledge with environment variables.
View Graphql_env.sh
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 Jul 11, 2022
Generated by SassMeister.com.
View input.scss
@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 Apr 26, 2022
Good bad and ugly Code
View good_bad_ugly_code.js
// 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
View Concepts.svg
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 Feb 7, 2020 — forked from beradrian/proxy.js
CORS proxy with node-http-proxy
View proxy.js
/** 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 Jan 30, 2020
Performance tips for O(n²) on JavaScript iterations.
View iteration_of_collections.js
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 Oct 15, 2019
"Setting up Jest and Enzyme for Typescript Next.js apps" post gists
View jest.config[2].js
module.exports = {
"testEnvironment": "node",
"roots": [
"<rootDir>/components"
],
"preset": 'ts-jest',
"setupFilesAfterEnv": ["<rootDir>/tests/setupTests.ts"],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
@Kjaer
Kjaer / tsconfig.jest.json
Last active Oct 15, 2019
"Setting up Jest and Enzyme for Typescript Next.js apps" post gists
View tsconfig.jest.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react"
}
}
@Kjaer
Kjaer / jest.config[1].js
Last active Oct 15, 2019
"Setting up Jest and Enzyme for Typescript Next.js apps" post gists
View jest.config[1].js
module.exports = {
"testEnvironment": "node",
"roots": [
"<rootDir>/components"
],
"preset": "ts-jest",
"setupFilesAfterEnv": ["<rootDir>/tests/setupTests.ts"],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
@Kjaer
Kjaer / Button.spec.tsx
Last active Oct 15, 2019
"Setting up Jest and Enzyme for Typescript Next.js apps" post gists
View Button.spec.tsx
import React from 'react';
import { mount } from 'enzyme';
test('hello world', () => {
 const wrapper = mount(<p>Hello Jest!</p>);
 expect(wrapper.text()).toMatch('Hello Jest!');
});