Skip to content

Instantly share code, notes, and snippets.

View igorjs's full-sized avatar
🌏
Away

igor.js igorjs

🌏
Away
View GitHub Profile
@igorjs
igorjs / .eslintrc
Created July 17, 2017 15:21 — forked from cletusw/.eslintrc
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
// Native selectors.
(function(window, document) {
'use strict';
var noop = function() {
};
// DOCUMENT LOAD EVENTS
// not needed at the bottom of the page
document.addEventListener('DOMContentLoaded', noop);
@igorjs
igorjs / rest-api-response-format.md
Last active June 29, 2024 20:14
REST API response format based on some of the best practices

1. Get your IP Address

echo `ifconfig $(netstat -nr | grep -e default -e "^0\.0\.0\.0" | head -1 | awk '{print $NF}') | grep -e "inet " | sed -e 's/.*inet //' -e 's/ .*//' -e 's/.*\://'`

2. Modify your hosts file

notepad

@igorjs
igorjs / ip.js
Created June 6, 2019 05:46 — forked from qiao/ip.js
Node.js get client IP address
// snippet taken from http://catapulty.tumblr.com/post/8303749793/heroku-and-node-js-how-to-get-the-client-ip-address
function getClientIp(req) {
var ipAddress;
// The request may be forwarded from local web server.
var forwardedIpsStr = req.header('x-forwarded-for');
if (forwardedIpsStr) {
// 'x-forwarded-for' header may return multiple IP addresses in
// the format: "client IP, proxy 1 IP, proxy 2 IP" so take the
// the first one
var forwardedIps = forwardedIpsStr.split(',');
export function localstorageMeta (key: string, reducer: any): any {
return function(state: any, action: any): any {
let nextState = reducer(state, action);
let storageState = JSON.parse(localStorage.getItem(key));
if (action.type === RESET_STATE || action.type.includes('DELETE')) {
localStorage.removeItem(key);
} else if (!state && storageState || action.type === '@@redux/INIT') {
nextState = storageState;
} else if (nextState && nextState !== storageState) {
@igorjs
igorjs / Await.js
Created September 14, 2019 17:55 — forked from evanrs/Await.js
React WaitOn component
const Promise = require('bluebird');
const React = require('react');
const superagent = require('superagent');
const assign = require('lodash/object/assign');
const isArray = require('lodash/lang/isArray');
const isFunction = require('lodash/lang/isFunction');
const isObject = require('lodash/lang/isArray');
const isString = require('lodash/lang/isString');
const log = require('debug')('component:await');
import FileService from './FileService'
import PDFService from './PDFService'
const SERVICE_PDF_URL = process.env.SERVICE_PDF_URL
export const getTemplateData = async (id, headers) => {
try {
// Preparte data for you template
return { }
} catch (err) {
@igorjs
igorjs / getParameterFromSystemManager.js
Created February 3, 2020 01:30
How to get and AWS SSM parameter using SDK
const AWS = require('aws-sdk');
const ssm = new AWS.SSM();
const getParameterFromSystemManager = async (key, isEncrypted = true) => {
// Fetches a parameter from SSM parameter store.
// Requires a policy for SSM:GetParameter on the parameter being read.
const params = {
Name: key,
const _ = require('lodash');
const Busboy = require('busboy');
const getContentType = (event) => {
// Serverless offline is passing 'Content-Type', AWS is passing 'content-type'
let contentType = _.get(event, 'headers.content-type');
if (!contentType) contentType = _.get(event, 'headers.Content-Type');
return contentType;
};