Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠

GP paambaati

🏠
View GitHub Profile
@paambaati
paambaati / README.md
Last active Nov 24, 2021
Generate yarn resolutions for audit-ci fixes
View README.md

How to use this

node auditResolutions.js

This will print some output that looks like this –

{"css-select@npm:2.1.0/nth-check":">=2.0.1"}
@paambaati
paambaati / localstorage_logout_sync.tsx
Last active Jul 28, 2022
Logging out of all tabs when logout occurs on 1 tab
View localstorage_logout_sync.tsx
// Your main component.
const MyComponentWrapper = (props) => {
// Watch changes to local storage, and if we logout in 1 tab,
// logout in every other tab.
const syncLogout = (event: StorageEvent): void => {
if (event.key === 'logout') {
Router.push('/login');
}
};
@paambaati
paambaati / select.tsx
Created Apr 12, 2020
react-select + react-hook-form
View select.tsx
import { forwardRef } from 'react';
import Select from 'react-select';
import { Controller } from 'react-hook-form';
import type { RefObject } from 'react';
import type { Props as ReactSelectProps } from 'react-select';
const Select = forwardRef(
(props: SelectProps, ref: RefObject<HTMLSelectElement>) => {
return (
<Controller
View node-liftbridge-grpc-trace.txt
GRPC_VERBOSITY=DEBUG GRPC_TRACE=all yarn run debug
yarn run v1.17.3
$ ts-node src/debug.ts
D0908 08:17:51.870543000 4400821696 dns_resolver.cc:294] Using native dns resolver
I0908 08:17:51.870996000 4400821696 timer_manager.cc:85] Spawn timer thread
I0908 08:17:51.871014000 4400821696 init.cc:163] grpc_init(void)
I0908 08:17:51.871060000 123145562341376 timer_manager.cc:246] timers not checked: expect another thread to
I0908 08:17:51.871069000 123145562341376 timer_manager.cc:194] sleep until kicked
I0908 08:17:51.871329000 4400821696 completion_queue.cc:504] grpc_completion_queue_create_internal(completion_type=0, polling_type=0)
View usa.geo.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paambaati
paambaati / marathon_migrate.py
Last active Feb 20, 2019
Handy script to help migrate all Mesos Marathon apps from 1 cluster to another. Can use either a Marathon URI or a local file location for both source & destination sinks. Works on both Python2 & Python3.
View marathon_migrate.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from os import environ
from json import load, loads, dumps
from urlparse import urlparse
try:
from urllib.request import urlopen, Request
from urllib.error import HTTPError
@paambaati
paambaati / map2json.js
Last active Jan 16, 2019
JSON stringifier that handles ES6 Maps
View map2json.js
// Optional: If any dependency is overriding Map's toJSON function,
// you might want to reset it.
// Why? See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior
delete Map.prototype.toJSON;
function customStringifier(key, value) {
if (value instanceof Map) {
// Convert Maps to JSON objects.
let obj = Object.create(null);
for (let [k, v] of value) {
@paambaati
paambaati / index.d.ts
Created Jan 7, 2019
Type definitions for chrome-remote-interface
View index.d.ts
// Type definitions for chrome-remote-interface 0.26.1
// Project: https://github.com/cyrus-and/chrome-remote-interface
// Definitions by: GP <https://github.com/paambaati>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = CDP;
declare function CDP(options?: CDP.ChromeRemoteInterfaceOptions): CDP.CDP;
declare namespace CDP {
@paambaati
paambaati / got.js
Last active Dec 24, 2018
Got with HTTP2 support (ALPN negotiation) + Connect settings overrides
View got.js
const {extend: gotExtend} = require('got');
const http2 = require('http2-wrapper');
const resolveALPN = require('resolve-alpn');
// Taken from https://github.com/nodejs/node/blob/d4c91f28148af8a6c1a95392e5c88cb93d4b61c6/lib/_http_agent.js
//
// throws
// tls.connect({host: 'httpbin.org', port: 443});
//
// doesn't throw
@paambaati
paambaati / PDFtoHTML.scala
Created Dec 19, 2018
Extracting HTML from PDFs
View PDFtoHTML.scala
package me
import java.io.{File, FileInputStream}
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.tools.PDFText2HTML
object PDFtoHTML {
def main(args: Array[String]): Unit = {
val stream = new FileInputStream(new File("/Users/me/Downloads/example.pdf"))