Skip to content

Instantly share code, notes, and snippets.

View namtx's full-sized avatar
🐤
Fullstuck developer

0x6e616d7478 namtx

🐤
Fullstuck developer
View GitHub Profile
@namtx
namtx / presenters.md
Created June 15, 2017 08:26 — forked from somebox/presenters.md
Thoughts About Rails Presenters

Thoughts about Rails Presenters

This is a collection of links, examples and rants about Presenters/Decorators in Rails.


The "Decorator" pattern slowly started gaining popularity in Rails several years ago. It is not part of core Rails, and there's many different interpretations about how it should work in practice.

Jay Fields wrote about it in 2007 (before he switched back to Java and then Clojure): http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

@namtx
namtx / postgres-cheatsheet.md
Created September 22, 2017 02:13 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@namtx
namtx / clear-sidekiq-jobs.sh
Created January 12, 2019 06:05 — forked from wbotelhos/clear-sidekiq-jobs.sh
Clear Sidekiq Jobs
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# 3. Clear 'Processed' and 'Failed' jobs
@namtx
namtx / axios.refresh_token.js
Created February 24, 2020 04:28 — forked from Godofbrowser/axios.refresh_token.1.js
Axios interceptor for refresh token when you have multiple parallel requests. Demo implementation: https://github.com/Godofbrowser/axios-refresh-multiple-request
// for multiple requests
let isRefreshing = false;
let failedQueue = [];
const processQueue = (error, token = null) => {
failedQueue.forEach(prom => {
if (error) {
prom.reject(error);
} else {
prom.resolve(token);
@namtx
namtx / useEffectDebugger.js
Created April 15, 2022 03:54 — forked from nvh95/useEffectDebugger.js
Find which dependency cause useEffect to fire
// Credit to https://stackoverflow.com/a/59843241/3422559
import { useEffect, useRef } from "react";
const usePrevious = (value, initialValue) => {
const ref = useRef(initialValue);
useEffect(() => {
ref.current = value;
});
return ref.current;