Skip to content

Instantly share code, notes, and snippets.

View msereniti's full-sized avatar
❤️‍🔥
Omae wa mou shindeiru... Nani?! ^c^c^c^c^c^c^c^c^c^c^c^c^c^

Michael Sereniti msereniti

❤️‍🔥
Omae wa mou shindeiru... Nani?! ^c^c^c^c^c^c^c^c^c^c^c^c^c^
  • Semrush
  • Barcelona, Spain
  • 16:36 (UTC +02:00)
  • X @msereniti
View GitHub Profile
@msereniti
msereniti / shallowMerge.ts
Last active February 4, 2022 09:40
Typescript shallow merge multiple objects
type ArrShift<Arr extends any[]> = Arr extends [skip: any, ...use: infer Use]
? Use
: Arr;
type ShallowMerge<Args extends any[]> = Args extends [any, any, any, ...any] ? Args[0] & ShallowMerge<ArrShift<Args>> : Args extends [any, any] ? Args[0] & Args[1] : Args[0]
type X = ShallowMerge<[{ x: 1 }, { y: 2 }, { z: 3}, { w: 4}]>
const x = 0 as any as X
@msereniti
msereniti / swiftui-like-view-modifiers.ts
Last active December 23, 2021 22:24
An attempt to create Typescript typing that adds context modifiers to parent functions when nested context consumers appears
type ArgumentTypes<F extends Function> = F extends (...args: infer A) => any
? A
: never;
type ArrShift<Arr extends any[]> = Arr extends [skip: any, ...use: infer Use]
? Use
: Arr;
type ViewSetup = {
modifiers: { [key: string]: (...args: any[]) => unknown };
@msereniti
msereniti / kill_unix_process_on_certain_port.md
Last active May 24, 2020 09:32
kill unix process on certain port

Command

kill -9 $(lsof -t -i:8080)

Detailed

To list any process listening to the port 8080:

lsof -i:8080

@msereniti
msereniti / cookies.js
Created November 19, 2018 07:30
Very simple cookie handler, that has 2 methods: get cookie and set cookie. Based on functions from https://learn.javascript.ru/cookie (old, russian version of javascript.info)
const cookie = {
get: name => {
const matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
},
set: (name, value, options={}) => {
const expires = options.expires;