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 / .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 / 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 / css-layout-hack.js
Last active April 17, 2020 08:29 — forked from vcastroi/css-layout-hack.js
CSS in JS #Javascript
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var elements = document.body.getElementsByTagName('*');
var items = [];
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.indexOf('* { background:#000!important;color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }') != -1) {
items.push(elements[i]);
}
}
var mimeTypes = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.wav': 'audio/wav',
@koyanloshe
koyanloshe / gist:108a05d99f25fe2e79d966eb2afa9d9b
Last active April 17, 2020 08:27
Generate multiple requests #Javascript
const {promisify} = require('util')
const sleep = promisify(setTimeout)
const request = async(data) => {
let time = Math.random() * 1000
await sleep(time)
return {data, time}
}
@koyanloshe
koyanloshe / Permissions
Created June 15, 2019 08:15
Linux Permissions #Linux
4 2 1
0 - - - no permissions
1 - - x only execute
2 - x - only write
3 - x x write and execute
4 x - - only read
5 x - x read and execute
6 x x - read and write
7 x x x read, write and execute
@koyanloshe
koyanloshe / Promise using .then() after a .get()
Last active June 15, 2019 08:18
Async request example #Javascript
var request = require("request");
var userDetails;
function getData(url) {
// Setting URL and headers for request
var options = {
url: url,
headers: {
'User-Agent': 'request'
}
@koyanloshe
koyanloshe / Art of naming variables
Last active June 15, 2019 08:18
Javascript Design Patterns #Javascript
// bad
const foo = y && z;
// good
const isPostEnabled = isPost && postDateValid;
/*The art of naming variables by Richard Tan[https://hackernoon.com/the-art-of-naming-variables-52f44de00aad]*/
@koyanloshe
koyanloshe / cloudSettings
Last active October 6, 2020 04:44
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-10-06T04:44:07.041Z","extensionVersion":"v3.4.3"}
@koyanloshe
koyanloshe / .editorconfig
Last active April 17, 2020 08:31
EditorConfig #Unix
# See https://github.com/RehanSaeed/EditorConfig for updates to this file.
# See http://EditorConfig.org for more information about .editorconfig files.
#################
# Common Settings
#################
# This file is the top-most EditorConfig file
root = true