Skip to content

Instantly share code, notes, and snippets.

@igorjs
igorjs / GetMultipartFormData.js
Last active February 7, 2020 00:44
Get the multipart FormData from the body
const getMultipartData = (request) => {
const foundKey = Object
.keys(request.headers)
.find(currentKey => currentKey.toLocaleLowerCase() === "content-type");
const boundary = request.headers[foundKey].split('=')[1];
const parts = request.body.split(boundary);
const files = [];
const fields = {};
@igorjs
igorjs / aws-apigateway-lambda-authorizer-blueprint.js
Last active April 17, 2024 04:27
aws-apigateway-lambda-authorizer-blueprint.js
/*
* Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
console.log('Loading function');
let suits = ["hearts", "spades", "clubs", "diamonds"];
let pickedNumber = Math.floor(Math.random() * 52);
let pickedSuit = Math.floor(pickedNumber / 13);
let pickedCard = {suit: suits[pickedSuit], card: pickedNumber % 13};
console.log("card: " + pickedCard.card + " of " + pickedCard.suit);
/*
Cell compete:
Eight houses, represented as a cells, are arranged as a straight line.
Each days every cells competes with adjacent cells. An integer value 1
represents an active cell and a value of 0 represent an inactive cell.
if the neigbour on both the sides of the cell are both active or inactive,
the cell become inactive in the next day, otherwise the become active.
The two cells on each or have a single adjacent cell, so asume that
the onoccupied space in the opposite side is an inactive cell. even after
updating the cell state, consider its previus state when updating the state
/*
The greatest common divisor (GCD), also called the highest common factor (HCF) of N numbers
is the largest positive integer that divides all numbers without giving a remainder.
Write an algorithm to determin the GCD of N positive integers.
https://codereview.stackexchange.com/questions/212591/find-the-greatest-common-divisor-of-n-numbers
*/
function generalizedGCD(num, arr) {
// Use spread syntax to get minimum of array
@igorjs
igorjs / base32.js
Last active May 21, 2020 01:25
A base32 reimplementation using native nodejs
(() => {
"use strict";
const __FORMAT_CHECK = /^[0123456789ABCDEFGHIJKLMNOPQRSTUV]+$/;
const __CHAR_MAP = '0123456789ABCDEFGHIJKLMNOPQRSTUV'.split('');
function __BASE32_ENCODE(inputData, map = null) {
if (!Buffer.isBuffer(inputData)) {
inputData = Buffer.from(inputData);
}
@igorjs
igorjs / configureStore.js
Created June 15, 2020 06:02 — forked from jarvisluong/configureStore.js
Custom redux persist version for redux-offline
//@flow
import { createStore, applyMiddleware } from 'redux';
import storage from 'redux-persist/lib/storage'
import { composeWithDevTools } from 'redux-devtools-extension';
import { persistStore, persistReducer } from 'redux-persist';
import thunk from 'redux-thunk';
import reducer from 'reducers';
import { createOffline } from '@redux-offline/redux-offline';
import offlineConfig from '@redux-offline/redux-offline/lib/defaults/index';
@igorjs
igorjs / README-Couchbase-Docker.adoc
Created June 15, 2020 06:34 — forked from HodGreeley/README-Couchbase-Docker.adoc
Docker Scripts to Simplify Setup with Couchbase

Docker Scripts to Simplify Setup with Couchbase

interface IXOptions {
a?: string,
b?: any,
c?: number
}
const XDefaults: IXOptions = {
a: "default",
b: null,
c: 1
@igorjs
igorjs / bitbucket-pipelines.yml
Created August 22, 2020 11:43 — forked from Gr1N/bitbucket-pipelines.yml
Why Drone CI can be interesting for you? Example of Bitbucket Pipelines configuration using YAML anchors and aliases
definitions:
caches:
poetry-path: /root/.poetry
poetry-venv: /root/.cache/pypoetry/virtualenvs
steps:
- step: &step-37
image: python:3.7
caches:
- poetry-path