Skip to content

Instantly share code, notes, and snippets.

Avatar

Gois guilhermejcgois

View GitHub Profile
@guilhermejcgois
guilhermejcgois / repo-scopes.sh
Last active Aug 29, 2019
Getting all scopes from commits summary in a repo for commitizen friendly repos
View repo-scopes.sh
git log --pretty="%s" | grep -o -P '(?<=\().*(?=\))' | grep -v -F 'pull request' | uniq
@guilhermejcgois
guilhermejcgois / md5-from-deps.js
Created Dec 17, 2018
Get MD5 hash from dependencies and devDependencies from a package.json
View md5-from-deps.js
const crypto = require('crypto');
const pjson = require('../package.json');
const depsStr = JSON.stringify(pjson.dependencies);
const devDepsStr = JSON.stringify(pjson.devDependencies);
const allDepsStr = depsStr + devDepsStr;
console.log(crypto.createHash('md5').update(allDepsStr).digest("hex"));
View ask-for-console-log.sh
#!/bin/sh
echo "\nChecking for console.logs()...\n"
# Get from http://frontend.turing.io/lessons/module-4/git-hooks.html
exec 1>&2
# enable user input
exec < /dev/tty
@guilhermejcgois
guilhermejcgois / tslint-pre-commit.sh
Created Sep 28, 2017
Run lint on typescript files before commit (under test)
View tslint-pre-commit.sh
#!/bin/bash
# Based on: https://github.com/observing/pre-commit/issues/50
# Stash modified files, but keep the index tree
git stash -q --keep-index
# 1. Run diff for tree index withtou create a new index tree, showing only files names and iff the file was added or copied or deleted or renamed.
# 2. Grep only for .ts files
# 3. Execute tslint for each file that was modified with type checking enabled
@guilhermejcgois
guilhermejcgois / getStyle.ts
Last active Sep 18, 2021
Get computed styles (in typescript)
View getStyle.ts
// Gist adapted from: https://gist.github.com/cms/369133
export getStyle(el: Element, styleProp: string): string {
let value;
const defaultView = el.ownerDocument.defaultView;
// W3C standard way:
if (defaultView && defaultView.getComputedStyle) {
// sanitize property name to css notation (hypen separated words eg. font-Size)
styleProp = styleProp.replace(/([A-Z])/g, '-$1').toLowerCase();
return defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
} else if (el['currentStyle']) { // IE
@guilhermejcgois
guilhermejcgois / 0_reuse_code.js
Created Jun 10, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console