Skip to content

Instantly share code, notes, and snippets.

View jayu's full-sized avatar
😁

Jakub Mazurek jayu

😁
View GitHub Profile
@jayu
jayu / extension.ts
Last active June 28, 2023 07:40
Install vscode extension from vsix file hosted in the internet. It's useful for distributing private, maybe paid version of your free extension.
import { Uri } from 'vscode'
import * as vscode from 'vscode'
import fetch from 'node-fetch'
export function activate(context: vscode.ExtensionContext) {
const installPrivateVersionOfExtension = () => {
const fileBlob = await (
// Most likely you want to authenticate user to execute that request
await fetch('https://your.server.com/extension.vsix')
).blob()
@jayu
jayu / pre-commit
Last active December 16, 2021 08:42
Git hook to detect console.log and todo added to codebase before commit
CONSOLE_LOGS="$(git diff HEAD | grep -e '^\+.*console.log' -ie '^\+.*todo')"
if [ ${#CONSOLE_LOGS} -ge 1 ] ; then
printf "😮 console.logs or todos found in commit diff!\n\n"
printf "$CONSOLE_LOGS\n\n"
echo '🛑 terminating'
exit 1
fi
@jayu
jayu / commit-msg
Created November 16, 2021 10:38
Git hook to validate commit message with cspell (Spell checker for Visual Studio Code)
#!/bin/sh
MSG_FILE="$1"
echo "🔄 Validating message: $(cat $MSG_FILE | grep --invert-match '#')"
cspell "$MSG_FILE"
# cspell should be installed -> yarn global add cspell
# save this file in .git/hooks/commit-msg
@jayu
jayu / config.js
Last active October 19, 2021 13:06
padding-line-between-statements nice config
{
"rules" : {
"padding-line-between-statements": [
"error",
{ "blankLine": "always", "prev": "block-like", "next": "*" }, // padding after code block
{ "blankLine": "always", "prev": "*", "next": "return" }, // padding before return
{ "blankLine": "always", "prev": "*", "next": "if" }, // padding before if statement
{ "blankLine": "always", "prev": "*", "next": "for" }, // padding before for loop
{ "blankLine": "always", "prev": "*", "next": "function" }, // padding before function
{ "blankLine": "always", "prev": "*", "next": "export" }, // padding before export
@jayu
jayu / index.js
Created May 19, 2020 10:32
Command execution time
const cp = require('child_process')
const results = []
for (let i = 0; i < 10; i++) {
const result = cp.execSync('yarn --cwd app build')
const resultString = result.toString()
const timeMatch = resultString.match(/\d\d\.\d\ds\./)
if (timeMatch === null) {
throw new Error('missing time result')
}
@jayu
jayu / babel.config.js
Created May 2, 2020 17:35
Linaria with Gatsby without plugins
module.exports = {
presets: [
'babel-preset-gatsby',
[
'linaria/babel',
{
evaluate: true,
displayName: process.env.NODE_ENV !== 'production'
}
],
@jayu
jayu / github-labels.js
Last active April 2, 2020 11:21
Get Github labels list in super-laberer-action format
var labels = [];
[].slice.call(document.querySelectorAll(".js-label-link"))
.forEach(function (element) {
labels.push({
name: element.textContent.trim(),
description: element.getAttribute("title") || "",
// using style.backgroundColor might returns "rgb(...)"
colour: element.getAttribute("style")
.replace("background-color:", "")
.replace(/color:.*/, "")
@jayu
jayu / script.sh
Created September 4, 2019 18:29
Rebuild a docker container i.e to restart app after code update
docker-compose up -d --no-deps --build
@jayu
jayu / run_android_emulator.sh
Last active January 31, 2019 16:01
Run android emulator from terminal
# change $NUMBER to number of emulator from list (emulator -list-avds)
emulator @$(emulator -list-avds | tr "\n" "," | cut -d ',' -f $NUMBER) > /dev/null 2>&1&