Skip to content

Instantly share code, notes, and snippets.

View acanimal's full-sized avatar

Antonio Santiago acanimal

View GitHub Profile
@acanimal
acanimal / table_sizes.sql
Created May 8, 2024 18:28
Postgres get table sizes
SELECT
relname AS "relation",
pg_size_pretty(pg_relation_size(C.oid)) AS "size",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "size_with_indexes"
FROM
pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE
nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
autocannon --connections 10 --duration 10 --headers content-type=application/json --method POST --body 'SOME JSON HERE' SOME_TARGET_URL
@acanimal
acanimal / open.sh
Created December 26, 2020 13:21
Open new instance of Google Chrome with different user data dir
open -na "Google Chrome" --args --user-data-dir=$SOME_FOLDER
@acanimal
acanimal / query.js
Created December 24, 2020 17:21
GraphQL query to get github user stats
import { Octokit } from "@octokit/rest";
// Go to github settings and create a token. Add permissions for user/email
const auth_token = 'YOUR TOKEN';
const octokit = new Octokit({
auth: auth_token,
});
const response = await octokit.graphql(`
@acanimal
acanimal / cra-sb.sh
Created August 12, 2018 12:19
create-react-app with storybook
$ npx create-react-app $PROJECT_NAME
$ cd $PROJECT_NAME
$ npm i -g @storybook/cli
$ getstorybook
$ yarn run storybook
@acanimal
acanimal / getDomainName.js
Last active August 17, 2018 16:16 — forked from tahirm/getDomainName.js
Get complete domain name with protocol and port if available. #js #urlFrom http://stackoverflow.com/questions/6941533/javascript-get-protocol-domain-and-port-from-url
const domain = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
@acanimal
acanimal / nest.js
Created March 10, 2018 10:21
Accessing nested object properties
// From: https://codeburst.io/accessing-nested-objects-in-javascript-c2ed249fe576
const getNestedObject = (nestedObj, pathArr) => {
return pathArr.reduce((obj, key) =>
(obj && obj[key] !== 'undefined') ? obj[key] : null, nestedObj);
}
@acanimal
acanimal / model-user.js
Last active February 17, 2020 15:34 — forked from lucasscariot/model-user.js
Composite Primary Key in Sequelize
/*
* Migration
*/
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('JobSkills', {
experience: {
type: Sequelize.INTEGER,
allowNull: false
},
@acanimal
acanimal / asyncMiddleware.js
Created December 6, 2017 16:05
Helper to use async middlewares
const asyncHandler = fn =>
(req, res, next) => {
Promise.resolve(fn(req, res, next))
.catch(next);
};
// Usage
express.get('/', asyncHandler(async (req, res, next) => {
const bar = await foo.findAll();
res.send(bar)
@acanimal
acanimal / withReduxProvider.js
Created March 24, 2017 08:25
High Order Component to wrap a component with redux Provider
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import initialState from './store/initialState';
import createStore from './store/createStore';
const store = createStore(initialState);
const getDisplayName = WrappedComponent => WrappedComponent.displayName || WrappedComponent.name || 'WrappedComponent';
/**
* HOC to wrap a component within redux provider to allow access the store.