Skip to content

Instantly share code, notes, and snippets.

View deadkff01's full-sized avatar
🪐

Dennis Kaffer deadkff01

🪐
View GitHub Profile
@deadkff01
deadkff01 / withGlobal.tsx
Created September 28, 2021 19:54
withGlobal HOC
import { FC, useCallback } from "react";
import { useGlobal, ACTIONS, GlobalContextProps } from "../contexts/global";
export interface IGlobal extends GlobalContextProps {
requestHandler: (requestFunction: () => {}) => Promise<any>;
}
interface IWrappedComponent {
global: IGlobal;
}
@deadkff01
deadkff01 / global.tsx
Created September 28, 2021 19:33
Global context example
import {
createContext,
useReducer,
useMemo,
useContext,
ReactNode
} from "react";
type ContextProps = {
isLoading: boolean;
@deadkff01
deadkff01 / useSwrConfig.js
Created July 19, 2020 00:53
useSwr config with axios and fetch
const api = axios.create({
baseURL: "http://localhost:8080/",
});
api.interceptors.response.use(
(response) => response.data,
(error) => Promise.reject(error)
);
export const useRequest = (config) => {
@deadkff01
deadkff01 / fibo.js
Last active June 23, 2020 01:06
Fibonacci implementations in js
// implementation with Array
const fibo = len =>
new Array(len).fill(1).reduce((acc, _, index) => {
const value =
index === 0 || index === 1
? index
: acc[acc.length - 2] + acc[acc.length - 1];
acc.push(value);
return acc;
}, []);
@deadkff01
deadkff01 / semantic-commit-messages.md
Created February 17, 2020 13:46 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@deadkff01
deadkff01 / objLiterals.js
Created November 15, 2019 21:44
Using an object as a switch case with javascript
// obj literals with javascript
const actions = {
'sayHello': name => `hello my friend ${name}`,
'typeOf': value => typeof value,
'onlyString': 'simple string',
'default': null
}
const reducer = (action, payload) => {
@deadkff01
deadkff01 / AsyncForEach.js
Last active September 12, 2019 13:26
Simple example of async foreach
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
const waitFor = ms => new Promise(r => setTimeout(r, ms));
asyncForEach([1, 2, 3], async num => {
await waitFor(50);
@deadkff01
deadkff01 / .eslintrc.js
Last active August 1, 2019 19:51
ESLint for nodejs
module.exports = {
env: {
es6: true,
node: true,
jest: true
},
extends: ['airbnb-base', 'prettier'],
plugins: ['prettier'],
globals: {
Atomics: 'readonly',
const { GraphQLObjectType, GraphQLList, GraphQLSchema, GraphQLInt, GraphQLString, GraphQLBoolean } = require('graphql')
const axios = require('axios')
// Launch Type
const LaunchType = new GraphQLObjectType({
name: 'Launch',
fields: () => ({
flight_number: { type: GraphQLInt },
mission_name: { type: GraphQLString },
launch_year: { type: GraphQLString },
launch_date_local: { type: GraphQLString },
@deadkff01
deadkff01 / settings.json
Last active July 19, 2019 14:27
Settings of VSCode
{
"javascript.updateImportsOnFileMove.enabled": "always",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true
},
"search.exclude": {