Skip to content

Instantly share code, notes, and snippets.

View sompylasar's full-sized avatar

Ivan Babak sompylasar

View GitHub Profile
@sompylasar
sompylasar / github-wiki-table-of-contents.js
Created January 22, 2019 23:09
While in the Wiki Edit (`/_edit`) Preview mode, run this snippet in the browser console to get a Markdown of a Table of contents. https://github.com/isaacs/github/issues/215
console.log(
'\n\n\n> **Table of contents**\n> \n' +
Array.from(document.querySelectorAll('h1 > a, h2 > a, h3 > a')).map((a) => (
{'H1':'> * ','H2':'> * ','H3':'> - '}[a.parentNode.tagName] +
`[${a.parentNode.innerText.trim()}](${a.hash})`
)).join('\n') +
'\n\n\n'
);
@sompylasar
sompylasar / runExternalProcessAsync.js
Created December 19, 2018 05:52
`Promise` wrapper around `require('child_process').spawn` that runs a process to completion with a given `stdin` and collects `stdout`, `stderr`, and the exit code.
const spawn = require('child_process').spawn;
async function runExternalProcessAsync({ procExecutable, procArgs, procStdinString }) {
const proc = await new Promise((resolve) => {
resolve(spawn(procExecutable, procArgs));
});
try {
return await new Promise((resolve, reject) => {
const procStdoutParts = [];
const procStderrParts = [];
@sompylasar
sompylasar / eslintParserForTypeScriptAndJavaScript.js
Last active December 17, 2018 22:13
Branching ESLint parser to consume both TypeScript (via typescript-eslint-parser) and JavaScript (via babel-eslint). Usage: in .eslintrc, "parser": "./eslintParserForTypeScriptAndJavaScript.js"
/* eslint-disable func-names, prefer-arrow-callback */
function isTypeScriptFilePath(filePath) {
return /\.tsx?$/.test(filePath);
}
function isTypeScriptCode(text) {
return (
/^\s*((declare\s+module)|(interface))\s+/m.test(text)
);
@sompylasar
sompylasar / nodeGracefulSigint.js
Last active December 19, 2018 05:40
Node.js process graceful interruption from SIGINT. Force termination after receiving certain number of SIGINTs.
const EventEmitter = require('events');
function gracefulSigint({ forceAttempts } = {}) {
let state = {
isEnabled: false,
isTerminating: false,
isTerminatingForce: forceAttempts >= 0 ? forceAttempts : 5,
};
let emitter = new EventEmitter();
let sigintHandler = () => {
@sompylasar
sompylasar / formatProgress.js
Last active January 11, 2019 19:43
Progress tracking and time estimate for a queue of similarly sized tasks.
const progressDefaultColor = typeof chalk !== 'undefined' ? chalk.magenta : (x) => x;
const progressErrorColor = typeof chalk !== 'undefined' ? chalk.red : (x) => x;
function formatProgress(startTime, queuedCount, finishedCount, errorsCount) {
const progressPercent = queuedCount > 0 ? (100 * finishedCount) / queuedCount : 100;
const errorsPercent = queuedCount > 0 ? (100 * errorsCount) / queuedCount : 0;
const elapsedTimeSeconds = (Date.now() - startTime) / 1000;
const itemsPerSecond = elapsedTimeSeconds > 0 ? finishedCount / elapsedTimeSeconds : 0;
const estimatedTimeSeconds = itemsPerSecond > 0 ? Math.max(0, (queuedCount - finishedCount) / itemsPerSecond) : 0;
return (
progressDefaultColor(
@sompylasar
sompylasar / .prettierrc
Last active November 22, 2018 21:36
Prettier config
{
"arrowParens": "always",
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"semi": true,
"useTabs": false,
"jsxBracketSameLine": false,
"printWidth": 120
}
.discussion-item-header[id^=ref-] .discussion-item-icon {
background-color: #6db2ff;
color: #ffffff;
}
.discussion-item-header[id^=ref-]::before {
content: '';
position: absolute;
display: block;
z-index: -1;
@sompylasar
sompylasar / gmail-2018.css
Last active September 27, 2018 22:21
Tweaks to the GMail look&feel (apply via Stylebot Chrome extension)
.hx .ii,
div.G3.G2.afm {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
div.T-I.J-J5-Ji.T-I-KE.L3 {
height: 30px;
margin: 0;
padding: 0 16px;
text-align: center;
justify-content: center;
@sompylasar
sompylasar / styles.less
Last active October 18, 2018 18:30
Atom 1.30: Adapt tree view and editor font size for large monitors (like the 27" ones). NOTE: This overrides the built-in editor text zoom feature (Cmd + / Cmd - / Cmd 0).
// Adapt tree view and editor font size for large monitors (like the 27" ones).
@media (min-width: 1800px) {
// Root font size
body {
font-size: 18px;
}
// Editor font size is specified separately
atom-workspace {
// NOTE: This overrides the built-in editor text zoom feature (Cmd + / Cmd - / Cmd 0).
#!/bin/bash
set -eu
REPO_PATH=$1
SHA=$2
if [[ ! -d "${REPO_PATH}" ]]; then
exit -1
fi