Skip to content

Instantly share code, notes, and snippets.

View nihalgonsalves's full-sized avatar

Nihal Gonsalves nihalgonsalves

View GitHub Profile
@nihalgonsalves
nihalgonsalves / Graphite GitHub PR button.user.js
Created July 28, 2023 11:45
Graphite GitHub PR button.user.js
// ==UserScript==
// @name Graphite GitHub PR button
// @description Add a button to go from app.graphite.dev to github.com
// @match https://app.graphite.dev/*
// @inject-into content
// @run-at document-start
// ==/UserScript==
const PATH_REGEX = /^\/github\/pr\/(\w+)\/(\w+)\/(\d+).*$/;
const SELECTOR =
@nihalgonsalves
nihalgonsalves / vite-plugin-customOptimizeDeps.ts
Last active June 24, 2021 01:40
Vite Plugin: Custom Optimize Deps
import path from 'path'
import { build, Plugin as EsbuildPlugin } from 'esbuild'
import { PluginOption } from 'vite'
// Since plugin support for the optimizeDeps phase isn't ready yet:
// https://github.com/vitejs/vite/pull/2886
// https://github.com/vitejs/vite/pull/2991
// We can exclude the deps and then optimize them ourselves.
// In the future, this plugin can be removed, and the plugin config
@nihalgonsalves
nihalgonsalves / eslintRuleCount.js
Last active August 17, 2020 20:35
Count eslint errors and warnings by rule name
const fs = require('fs')
// run e.g. `eslint . --ext .js,.ts,.tsx --fix > errors.txt` first
const data = fs.readFileSync('errors.txt', 'utf8')
const errors = data
.split('\n')
.filter(line => line.includes('warning') || line.includes('error'))
// retrieve the last "word" of the output
// eg: `1:1 warning Prefer named exports import/no-default-export`
@nihalgonsalves
nihalgonsalves / generateKotlinHttpStatusObject.js
Last active June 14, 2019 10:36
Generate a Kotlin HttpStatus object from the data at @for-GET/know-your-http-well
const fs = require('fs');
// requires this file:
// https://raw.githubusercontent.com/for-GET/know-your-http-well/master/json/status-codes.json
const generateKotlinHttpStatusObject = () => {
const codes = JSON.parse(fs.readFileSync('status-codes.json', 'utf8'));
const values =
codes
.filter(({ code }) => /^\d+$/.test(code))
@nihalgonsalves
nihalgonsalves / raw_post.html
Created November 3, 2017 09:56
POST raw application/x-www-form-urlencoded data from a browser
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script>
const url = 'https://postman-echo.com/post';
// params are expected as raw application/x-www-form-urlencoded data
// example: "foo=x&bar=hello%20world"
@nihalgonsalves
nihalgonsalves / exif_date_from_filename.rb
Created October 10, 2017 07:43
Fix EXIF metadata using a filename pattern
require 'mini_exiftool'
files = Dir["./*.jpg"]
loaded_images = files.map{|f| MiniExiftool.new(f)}
def extract_date(image, timezone="+05:30")
# hacky, but does the job
filename = image.instance_variable_get("@filename")
extractor = Regexp.new(/\.\/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})_(?<hour>\d{2})-(?<min>\d{2})-(?<sec>\d{2}).*/)