Skip to content

Instantly share code, notes, and snippets.

View Kyoss79's full-sized avatar

Kyoss Kyoss79

  • PixelDojo
  • Munich, Germany
View GitHub Profile
@Kyoss79
Kyoss79 / useLocalStorage.ts
Created December 12, 2022 12:57
React useLocalStorage
import { useState } from 'react';
export const useLocalStorage = <ValueType>(
keyName: string,
defaultValue?: ValueType,
deserialize = JSON.parse,
serialize = JSON.stringify
): [ValueType | undefined, (newValue: ValueType) => void] => {
const [storedValue, setStoredValue] = useState<ValueType | undefined>(() => {
const value = globalThis.localStorage?.getItem(keyName);
<?php
// lets assume we have an error object
// from a laravel API like the following:
$errorResponse = [
'errors' => [
'bike.name' => ['required'].
'locks.0.rrp' => ['min:49'],
'cancel_url' => ['required]
]
];
@Kyoss79
Kyoss79 / notion.ts
Created May 29, 2021 10:35
Example Typescript implementation of Notion.so API
import { Client } from '@notionhq/client';
import { Block, User } from '@notionhq/client/build/src/api-types';
export type ITodo = {
id: string;
title: string;
assignedTo: User[];
dateCreated: Date;
dueDate: Date[];
priority: string;
@Kyoss79
Kyoss79 / numeric.directive.ts
Created July 26, 2019 14:38
Working example of a directive, that converts input fields which have been masked with textMask to a valid number in the ngModel
import { Directive, ElementRef, HostListener, Output, EventEmitter } from '@angular/core';
import { NgControl } from '@angular/forms';
@Directive({
selector: '[numeric]'
})
export class NumericDirective {
@Output() ngModelChange: EventEmitter<any> = new EventEmitter<any>(false);
constructor(
@Kyoss79
Kyoss79 / numeric.directive.ts
Last active February 9, 2020 23:06
Working example of a directive, that converts input fields which have been masked with textMask to a valid number in the ngModel (Original Discussion found here: https://github.com/text-mask/text-mask/issues/109)
import { Directive, ElementRef, HostListener, Output, EventEmitter } from '@angular/core';
import { NgControl } from '@angular/forms';
@Directive({
selector: '[numeric]'
})
export class NumericDirective {
@Output() ngModelChange: EventEmitter<any> = new EventEmitter<any>(false);
constructor(
@Kyoss79
Kyoss79 / localStorageService.expire.js
Last active April 1, 2019 09:39
Extend the localStorageService for Angular (https://github.com/grevory/angular-local-storage) with the possibility of expiring entries.
/**
* extend the localStorageService (https://github.com/grevory/angular-local-storage)
*
* - now its possible that data stored in localStorage can expire and will be deleted automagically
* - usage localStorageService.set(key, val, expire)
* - expire is an integer defininig after how many hours the value expires
* - when it expires, it is deleted from the localStorage
*/
app.config(($provide) => {
$provide.decorator('localStorageService', ($delegate) => {