Skip to content

Instantly share code, notes, and snippets.

View uhtred's full-sized avatar

Daniel França uhtred

View GitHub Profile
@uhtred
uhtred / lodash.toggle-array-value.js
Created September 26, 2016 20:55
Lodash: toggle array value
_.xor([1], [2]);
= [1, 2]
_.xor([1, 2], [2]);
= [1]
@uhtred
uhtred / gist:ef1739b76971b3d0e985
Created January 25, 2016 15:59 — forked from guilherme/gist:9604324
Git pre-commit hook that detects if the developer forget to remove all the javascript console.log before commit.
#!/bin/sh
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
consoleregexp='console.log'
# CHECK
if test $(git diff --cached | grep $consoleregexp | wc -l) != 0
then
@paulirish
paulirish / what-forces-layout.md
Last active May 31, 2024 22:37
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
$spaces: 10;
$spaces-step: 5px;
@mixin make-spaces ($class) {
.space-#{$class}-0 {
margin-bottom: 0;
}
@for $i from 1 through $spaces {
.space-#{$class}-#{$i} {
var webviewProvider = (function() {
if (/\/FBIOS/i.test(navigator.userAgent) === true) {
return 'facebook';
}
if (/Twitter for/i.test(navigator.userAgent) === true) {
return 'twitter';
}
if (/Pinterest\//.test(navigator.userAgent) === true) {
return 'pinterest';
}
@uhtred
uhtred / mixin-triangle.scss
Last active August 29, 2015 14:05
SASS: Triangle Mixin
@mixin triangle( $orientation: 'right', $size: 5px, $color: #000000 ) {
width: 0;
height: 0;
$listH: right, left;
$listV: up, down;
@if index( $listH, $orientation ) {
border-top: $size solid transparent;
border-bottom: $size solid transparent;
@phlbnks
phlbnks / Pure CSS Offsets
Last active July 23, 2019 08:01
CSS to add offsets to Pure grids http://purecss.io/
/*
Offsets from https://raw.githubusercontent.com/tilomitra/pure/d7f85e37abec3fdab14a541305ad05783159655c/src/grids/css/grids-offsets.css
Media queries from Pure v0.5.0
Copyright 2014 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
https://github.com/yui/pure/blob/master/LICENSE.md
*/
@media screen and (min-width: 35.5em) {
.offset-sm-0 {
margin-left:0;
@Stanback
Stanback / nginx.conf
Last active February 4, 2022 18:05
Example Nginx configuration for serving pre-rendered HTML from Javascript pages/apps using the Prerender Service (https://github.com/collectiveip/prerender).Instead of using try_files (which can cause unnecessary overhead on busy servers), you could check $uri for specific file extensions and set $prerender appropriately.
# Note (November 2016):
# This config is rather outdated and left here for historical reasons, please refer to prerender.io for the latest setup information
# Serving static html to Googlebot is now considered bad practice as you should be using the escaped fragment crawling protocol
server {
listen 80;
listen [::]:80;
server_name yourserver.com;
root /path/to/your/htdocs;
@dfkaye
dfkaye / js-get-fn-name.js
Last active October 31, 2022 11:44
get a javascript function name
function getFnName(fn) {
fn = Object(fn)
var F = typeof fn == 'function'
var N = fn.name
var S = F && ((N && ['', N]) || fn.toString().match(/function ([^\(]+)/))
return (!F && 'not a function') || (S && S[1] || 'anonymous');
}
console.log(getFnName(String)); // 'String'
console.log(getFnName(function test(){})); // 'test'
@ricardobarantini
ricardobarantini / README.md
Last active April 24, 2024 18:00
Hack para centralizar div do Bootstrap

Modo de usar

Bootstrap 3

Basta chamar a classe "centered" nas divs com a classe "col-lg-", "col-md-", "col-sm-" ou "col-xs-" (1-12).