Skip to content

Instantly share code, notes, and snippets.

@MikelArnaiz
MikelArnaiz / input.scss
Created November 18, 2021 08:53
Generated by SassMeister.com.
@mixin byPlatform($type) {
@if $type == 'mobile' {
font-size: 8px;
line-height: 10px;
}
@if $type == 'table' {
font-size: 12x;
line-height: 15px;
}
@MikelArnaiz
MikelArnaiz / aboutEnums.ts
Created July 23, 2021 08:39
Union types vs enums vs const assertions
const ALIGN_LEFT = 'left'
const ALIGN_RIGHT = 'right'
type AlignUnion = typeof ALIGN_LEFT | typeof ALIGN_RIGHT
const foo: AlignUnion = 'bar'
const foo1: AlignUnion = 'left'
const foo2: AlignUnion = ALIGN_LEFT
enum AlignEnum {
@MikelArnaiz
MikelArnaiz / regex
Created July 20, 2021 16:07
Regex to replace text in VS code in between two words multiline
Search:
export const dispatchToProps = \{((.|\n)+)\};
Replace:
export const dispatchToProps = () => ({$1});
Or:
export const dispatchToProps = \{(.*?)\};
@MikelArnaiz
MikelArnaiz / DecodeJSON.ts
Created July 5, 2021 07:05
Decode expected JSON and map it to expected result
// Attempt 1
function decodeJson(json: unknown) {
return <A, R>(
expectedInput: Decoder<unknown, A>,
expectedOutput: Decoder<unknown, R>,
fn: (a: A) => R
): Either.Either<Decoding, R> => {
pipe(
json,
@MikelArnaiz
MikelArnaiz / package.json
Created July 1, 2021 08:40
Merge prettierignore and gitignore
{
"scripts": {
"prettier:check": "./bin/prettier.sh --check",
"prettier:fix": "./bin/prettier.sh --write",
}
}
@MikelArnaiz
MikelArnaiz / readme.md
Last active June 1, 2021 11:44
Detect circular dependencies
@MikelArnaiz
MikelArnaiz / fake-api-restaurants.json
Last active April 12, 2021 17:28
fake api restaurants
[
{
"id": "1",
"name": "Bella Italia",
"menu": [
{
"name": "🍕 4 formaggi",
"price": 10
},
{
@MikelArnaiz
MikelArnaiz / example.js
Created March 30, 2021 19:30
Set scroll to percentage
const container = document.getElementById('container')
const percentage = 50
// getComputedStyle in case container has borders
const containerWidth = parseInt(getComputedStyle(container, null).width, 10)
container.scrollLeft = ((container.scrollWidth - containerWidth) / 100 ) * percentage
@MikelArnaiz
MikelArnaiz / useColorScheme.ts
Last active September 23, 2020 16:32
Hook ColorScheme, is dark mode etc
import { useState, useEffect } from 'react'
export enum ColorScheme {
Dark = 'dark',
Light = 'light',
NoPreference = 'no-preference',
}
export const useIsColorScheme = (colorScheme: ColorScheme) => {
const [isColorScheme, setIsColorScheme] = useState<boolean>(false)
@MikelArnaiz
MikelArnaiz / sort.ts
Created September 16, 2020 08:08
Sort compare function with key accessor
type FilteredKeys<T, U> = { [P in keyof T]: T[P] extends U ? P : never }[keyof T]
const compare = <T>(fn: (x: T, y: T) => number) => <O extends object>(key: FilteredKeys<O, T>) => (
a: O,
b: O,
): number => {
const valA = (a[key] as unknown) as T
const valB = (b[key] as unknown) as T
return fn(valA, valB)