Skip to content

Instantly share code, notes, and snippets.

View acanimal's full-sized avatar

Antonio Santiago acanimal

View GitHub Profile
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 / specification.js
Last active November 4, 2020 09:40
Specification pattern in JavaScript
"use strict";
/**
* Specification base class
* @class
*/
var Specification = {
and: function(spec) {
return new AndSpecification(this, spec);
},
@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 / error_class_es6.js
Created January 10, 2017 16:02
Custom error in ES6
class ExtendableError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
this.message = message;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = (new Error(message)).stack;
}
@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 / 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 / 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 / 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)