Skip to content

Instantly share code, notes, and snippets.

@NikhilVerma
NikhilVerma / FizzBuzz.js
Created December 11, 2012 14:06
A simple JS FizzBuzz solution
for(var i = 1; i <= 100; i++){
console.log(i%3 === 0 && i%5 === 0 && 'FizzBuzz' || i%3 === 0 && 'Fizz' || i%5 === 0 && 'Buzz' || i);
}
@NikhilVerma
NikhilVerma / gist:5620183
Last active December 17, 2015 13:49
Calculate the frame rate at which the current browser is rendering the frame at
(function(){
var TO_RUN = 20;
var sum = count = time = last = 0;
var first = false; // ignore the first time loop
var fn = function(){
time = new Date().getTime();
if(first === true){
sum += time - last;
@NikhilVerma
NikhilVerma / git-contributions.sh
Created August 16, 2016 08:37
Useful shell scripts
git ls-tree --name-only -r HEAD | egrep -Z -E -a '\.(js|less|html|markdown|md|svg|sh|php)$' | xargs -n1 git blame -w -M -C --line-porcelain | grep "^author " | sort | uniq -c | sort -nr
@NikhilVerma
NikhilVerma / cloudSettings
Last active December 20, 2019 14:08
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-12-20T14:05:56.227Z","extensionVersion":"v3.4.3"}
/**
* Simple implementation of LRU + SWR cache approaches to enable fast cache retrieval at the same time allowing refresh in the background
*/
import LRUCache from 'lru-cache';
const lruCache = new LRUCache<string, CacheFormat<any>>({
max: 1000,
maxAge: Infinity,
// These two options are reduntant since we cache forever, but if we decide to change it
@NikhilVerma
NikhilVerma / ast-finder.ts
Created September 16, 2020 07:27
AST Finder
/**
* This file is a tool to "grep" for code by using Abstract syntax trees
* It allows developers to do refactorings by searching for code patterns
* which would be hard to express using regular expressions
*/
import { parse, ParserPlugin } from '@babel/parser';
import traverse, { NodePath, TraverseOptions } from '@babel/traverse';
import chalk from 'chalk';
import fs from 'fs';
@NikhilVerma
NikhilVerma / find-git-contributions.sh
Created March 17, 2021 20:15
This gist is a fast way to get line contributions in git per author.
########################################################################
# This gist is a fast way to get line contributions in git per author. #
# The results should not be intepreted seriously, line-contributions #
# are a weak indicator of the value of someone's contribution. #
########################################################################
# If you have GNU parallel utility installed (recommended)
git ls-tree --name-only -r HEAD | parallel --eta "git blame -w -M -C --line-porcelain {} | grep \"^author \"" | sort -S 20G | uniq -c | sort -nr
@NikhilVerma
NikhilVerma / highlight-data-qa.js
Last active December 2, 2021 09:53
Highlights data-qa attributes on the page
var observer;
if (observer) {
observer.disconnect();
}
observer = new MutationObserver((mutationsList, observer) => {
mutationsList.forEach(mutation => {
if (mutation.addedNodes?.length > 0) {
mutation.addedNodes.forEach(highlightQaAttributes);
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const { isObject, some } = require("lodash");
const utilsOriginal = require("eslint-plugin-vue/lib/utils");
const casing = require("eslint-plugin-vue/lib/utils/casing");
const cloneDeep = require("lodash/cloneDeep");
const utils = cloneDeep(utilsOriginal);
@NikhilVerma
NikhilVerma / lint-staged.config.js
Created November 9, 2022 05:22
Using pre-push hooks for validation
module.exports = {
"**/*.{ts?(x),vue}": () => "tsc",
"**/*.{ts?(x),vue,js?(x)}": "yarn lint",
"**/*.{vue,ts?(x),js?(x)}": () => "env CI=true yarn test:unit",
"{package.json,yarn.lock}": () => "yarn check --integrity"
};