Skip to content

Instantly share code, notes, and snippets.

View IhsanMujdeci's full-sized avatar

IhsanMujdeci IhsanMujdeci

View GitHub Profile
@IhsanMujdeci
IhsanMujdeci / ts
Created September 19, 2019 05:22
User Typed Selector
import {RootType} from "../rootreducer";
import {useSelector} from "react-redux";
export function useTypedSelector<T>(
selector: (state: RootType) => T,
equalityFn?: (left: T, right: T) => boolean): T {
return useSelector<RootType, T>(selector, equalityFn);
}
const obj = {
a: 1,
deeper:{
val: "lol",
amArr: ['uuh', 'yuh']
},
b:{
c:{
val: 2,
arr: [3,4,5],
import request from 'request-promise'
class User{
emailUrl = "emailserver.com/api"
constructor(
private firstName: string,
private lastName: string,
private age: number,
private email: string,
){}
export type MockedInterface<T> = {
[K in keyof T]: T[K] extends (...args: infer A) => infer B
? jest.Mock<B, A>
: MockedInterface<T[K]>;
};
export function mockInterface<T>(
initialValue: { [K in keyof T]?: MockedInterface<T[K]> } = {}
): MockedInterface<T> {
const source = {
# Will print out 10 latest worked on git branches with (author, lasted worked, name) with a star on your active branch
git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
@IhsanMujdeci
IhsanMujdeci / useDocumentScroll.ts
Last active August 12, 2021 02:19
useScrollBody
import { useEffect, useState } from 'react';
export default function useDocumentScrollBottom(offset: number = 0): boolean {
const [atBottom, setAtBottom] = useState(false);
useEffect(() => {
const el = document;
let timeoutId: any;
type Accumulation struct {
messages []interface{}
t *time.Timer
}
// Accumulator debounces and accumulates values then sends them to function passed in the Add method
// Implements a concurrency safe map that can accumulate messages based on a key
type Accumulator struct {
acc map[string]*Accumulation
mu sync.Mutex
ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'