Skip to content

Instantly share code, notes, and snippets.

View jbutko's full-sized avatar

Jozef Butko jbutko

View GitHub Profile
@fnky
fnky / hooks.js
Last active January 7, 2024 12:32
React Hooks: useReducer with actions and selectors (Redux-like)
function useSelectors(reducer, mapStateToSelectors) {
const [state] = reducer;
const selectors = useMemo(() => mapStateToSelectors(state), [state]);
return selectors;
}
function useActions(reducer, mapDispatchToActions) {
const [, dispatch] = reducer;
const actions = useMemo(() => mapDispatchToActions(dispatch), [dispatch]);
return actions;
@devdoomari3
devdoomari3 / hoc-template.tsx
Last active December 19, 2019 08:10 — forked from rosskevin/hoc-template.tsx
Typescript higher order component (hoc) template
/* variation on https://medium.com/@DanHomola/react-higher-order-components-in-typescript-made-simple-6f9b55691af1 */
import * as React from 'react'
import { wrapDisplayName } from 'recompose'
// Props you want the resulting component to take (besides the props of the wrapped component)
interface ExternalProps {}
// Props the HOC adds to the wrapped component
export interface InjectedProps {}
@mksglu
mksglu / LoadingHOC.tsx
Created August 4, 2018 19:10
ReactJS and TypeScript High Order Component (HOC) Loading Spinner
import * as React from 'react';
interface IProps {
propName?: any;
loadingTime?: boolean;
}
const loadingHOC = ({ propName, loadingTime = false }: IProps) => <
P extends {}
>(
WrappedComponent: React.ComponentClass<P> | React.StatelessComponent<P>

If .DS_Store was never added to your git repository, simply add it to your .gitignore file.

If you don't have one, create a file called

.gitignore

In your the root directory of your app and simply write

@MiguelCedric
MiguelCedric / agenda.js
Created March 8, 2018 20:45
Agenda Configuration
const Agenda = require('agenda');
const mongoConnectionString = 'mongodb://localhost:27017/yourdatabase';
// or override the default collection name:
let agenda = new Agenda({db: {address: mongoConnectionString, collection: 'jobs'}});
let jobTypes = process.env.JOB_TYPES ? process.env.JOB_TYPES.split(',') : [];
jobTypes.forEach(function(type) {
@DZuz14
DZuz14 / signup-user.js
Last active June 25, 2019 14:07
Async Await Action Creator with Redux Thunk
const BACKEND_URL = 'https://fakeserver.com/api'
export function signUpUser(email, password) {
return async (dispatch) => {
try {
const signUp = await axios.post(`${BACKEND_URL}/signup`, {
email: email,
password: password
})
@rafaelrozon
rafaelrozon / mock_axios_storybook.jsx
Last active April 26, 2023 12:29
Mock Axios requests in Storybook
import React from 'react';
import { storiesOf } from '@storybook/react';
// 1. import axios and MockAdapter
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
// 2. create the mock
const mock = new MockAdapter(axios);
@GantMan
GantMan / NEW_OPENSOURCE_TODO.md
Last active December 27, 2021 23:20
ALL the things to do when starting a new Github Project - IR JavaScript | TypeScript

Step 1 - Create nest on Github

  1. Click Plus
  2. New Repository
  3. IR/REPO_NAME
  4. PROJECT_DESCRIPTION
  5. Do not initialize with anything (easier to add after)
  6. Star your repo
  7. Pull your repo down locally and cd to it
@ziluvatar
ziluvatar / token-generator.js
Last active April 8, 2025 08:12
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');
@servercharlie
servercharlie / steps.txt
Last active October 7, 2019 16:41
Setting up NodeJS w/ NPM + PM2 on Ubuntu 16.10 (Yakkety Yak!)
> SSH Login to your home directory.
> Get APT updates & upgrades.
sudo apt-get update
sudo apt-get upgrade
> NodeJS & NPM
> https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
> Installs the latest NodeJS & NPM, including the essential build tools (used by most packages).