Skip to content

Instantly share code, notes, and snippets.

@NikhilVerma
NikhilVerma / App.vue.ts
Created August 21, 2023 13:57
Volar generated virtual file for App.vue
View App.vue.ts
/**
// App.vue
<script setup lang="ts">
import HelloWorld from "./components/HelloWorld.vue";
import Header from "./components/Header.vue";
import HeaderAlt from "./components/HeaderAlt.vue";
const isAlternateHeader = Math.random() > 0.5;
const items = [1, 2, 3];
@NikhilVerma
NikhilVerma / lint-staged.config.js
Created November 9, 2022 05:22
Using pre-push hooks for validation
View lint-staged.config.js
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"
};
View no-unused-components.js
// ------------------------------------------------------------------------------
// 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 / highlight-data-qa.js
Last active December 2, 2021 09:53
Highlights data-qa attributes on the page
View highlight-data-qa.js
var observer;
if (observer) {
observer.disconnect();
}
observer = new MutationObserver((mutationsList, observer) => {
mutationsList.forEach(mutation => {
if (mutation.addedNodes?.length > 0) {
mutation.addedNodes.forEach(highlightQaAttributes);
@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.
View find-git-contributions.sh
########################################################################
# 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 / ast-finder.ts
Created September 16, 2020 07:27
AST Finder
View ast-finder.ts
/**
* 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';
View swr-lru-node.ts
/**
* 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 / cloudSettings
Last active December 20, 2019 14:08
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2019-12-20T14:05:56.227Z","extensionVersion":"v3.4.3"}
@NikhilVerma
NikhilVerma / git-contributions.sh
Created August 16, 2016 08:37
Useful shell scripts
View git-contributions.sh
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 / gist:5620183
Last active December 17, 2015 13:49
Calculate the frame rate at which the current browser is rendering the frame at
View gist:5620183
(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;