Skip to content

Instantly share code, notes, and snippets.

Ivan Babak sompylasar

Block or report user

Report or block sompylasar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sompylasar
sompylasar / github-wiki-table-of-contents.js
Created Jan 22, 2019
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
View github-wiki-table-of-contents.js
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 Dec 19, 2018
`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.
View runExternalProcessAsync.js
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 Dec 17, 2018
Branching ESLint parser to consume both TypeScript (via typescript-eslint-parser) and JavaScript (via babel-eslint). Usage: in .eslintrc, "parser": "./eslintParserForTypeScriptAndJavaScript.js"
View 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 Dec 19, 2018
Node.js process graceful interruption from SIGINT. Force termination after receiving certain number of SIGINTs.
View nodeGracefulSigint.js
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 Jan 11, 2019
Progress tracking and time estimate for a queue of similarly sized tasks.
View formatProgress.js
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 Nov 22, 2018
Prettier config
View .prettierrc
{
"arrowParens": "always",
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"semi": true,
"useTabs": false,
"jsxBracketSameLine": false,
"printWidth": 120
}
View github-ux-distinct-referenced-commits.css
.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 Sep 27, 2018
Tweaks to the GMail look&feel (apply via Stylebot Chrome extension)
View gmail-2018.css
.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 Oct 18, 2018
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).
View styles.less
// 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).
View sourcetree-open-github-commit-url.sh
#!/bin/bash
set -eu
REPO_PATH=$1
SHA=$2
if [[ ! -d "${REPO_PATH}" ]]; then
exit -1
fi
You can’t perform that action at this time.