Skip to content

Instantly share code, notes, and snippets.

View koyanloshe's full-sized avatar
👁️
Focusing

Alok Shenoy koyanloshe

👁️
Focusing
View GitHub Profile
@koyanloshe
koyanloshe / memoization.js
Last active April 17, 2020 08:29
Memoization #Javascript
const memoizeUtil = func => {
// results store
const cache = {};
return (input) => {
// return the value if it exists in the cache object
// otherwise, compute the input with the passed in function and
// update the collection object with the input as the key and
// computed result as the value to that key
// End result will be key-value pairs stored inside cache
return cache[input] || (cache[input] = func(input));
@koyanloshe
koyanloshe / .vimrc
Last active April 17, 2020 08:28
Vim Config #vim
https://github.com/amix/vimrc
let g:javascript_plugin_jsdoc = 1
let g:javascript_conceal_arrow_function = "⇒"
@koyanloshe
koyanloshe / server.js
Last active April 17, 2020 08:28
Basic server for most filetypes #Javascript
var http = require('http');
var fs = require('fs');
var path = require('path');
http.createServer(function (request, response) {
console.log('request ', request.url);
var filePath = '.' + request.url;
if (filePath == './') {
filePath = './index.html';
@koyanloshe
koyanloshe / basic.vim
Last active April 17, 2020 08:26 — forked from gaveen/basic.vim
Gists for the blog post about vimfiles at: https://gaveen.me/2020/02/my-vim-story/ #vim
" Basic settings
set nocompatible " behave like vim, not old vi
set modelines=0 " don't use modelines
set viminfo='20,\"50 " use a viminfo file,...
set history=50 " and limit history
set ruler " show the cursor position
set title " show title on the window
set autoread " reload file if changed outside vim
set autowrite " save file on some commands
set scrolloff=1 " minimal no. of lines around cursor
@koyanloshe
koyanloshe / cloneObj
Last active April 17, 2020 08:27
Cloning objects without effects #Javascript
// Object.assign has an issue with nested Objects. This prevents that leakage
const cloneObj = (existingObj) => {
return JSON.parse(JSON.stringify(existingObj))
}
@koyanloshe
koyanloshe / Promisified compose in Javascript
Last active August 10, 2022 19:19
Pipe & Compose in Javascript #Javascript #fp
// Async compose
const compose = (…functions) => input => functions.reduceRight((chain, func) => chain.then(func), Promise.resolve(input));
// Functions fn1, fn2, fn3 can be standard synchronous functions or return a Promise
compose(fn3, fn2, fn1)(input).then(result => console.log(`Do with the ${result} as you please`))
@koyanloshe
koyanloshe / env.js
Last active April 17, 2020 08:28
process.env setter #Javascript
const fs = require('fs')
const rootDir = require('../utils/rootDir')
const env = {
// accepts a filename and if no filename, it defaults to .env
config: filename => {
filename === undefined ? (filename = '.env') : filename
fs.readFileSync(`${rootDir}/${filename}`, 'utf-8')
@koyanloshe
koyanloshe / trace.js
Last active April 17, 2020 08:34
Software composition by Eric Eliott #Javascript #fp
const trace = label => value => {
console.log(`{$label} : {$value}`);
return value;
}
@koyanloshe
koyanloshe / postgres-brew.md
Created May 5, 2020 18:08 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@koyanloshe
koyanloshe / byteSize.js
Last active June 6, 2020 16:44
Utility functions
function bytesToSize (bytes) {
if (bytes === 0) return '0 B';
var k = 1024;
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
var i = Math.floor(Math.log(bytes) / Math.log(k))
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i]
}