Skip to content

Instantly share code, notes, and snippets.

View fregante's full-sized avatar

Federico Brigante fregante

View GitHub Profile
@fregante
fregante / header.js
Last active May 21, 2016 12:01 — forked from dominikwilkowski/00-README.md
Doc strange outline love (jQuery-free)
//detecting tab key press
document.body.addEventListener('keydown', function detector (e) {
var keyCode = e.keyCode || e.which;
if(keyCode == 9) {
console.log( 'Tab detected' );
document.documentElement.className += ' is-keyboarduser';
document.body.removeEventListener('keydown', detector);
@fregante
fregante / moved.md
Last active December 26, 2016 14:40
If you preventDefault on clicks, wrap the handler with this
@fregante
fregante / moved.md
Last active March 6, 2016 14:51
Play video inline on iPhone
@fregante
fregante / git-get-git-put.md
Created June 30, 2015 18:34
Use git get and put instead of git pull and push

As explained on Don't Be Scared of git rebase, git fetch+rebase is a better alternative to git pull; unfortunately it's not as concise.

git get

From now on, use git get instead of git pull, a custom command that does this:

# get data from remote
git fetch origin
# rebase the remote branch with the same name as local
@fregante
fregante / README.md
Last active August 29, 2015 14:12
Fix Yosemite's asymmetrical Time Machine menu icon

The asymmetrical Time Machine menu icon in Yosemite was bugging me, so I fixed it.

Icon comparison

Here's how to do it:

  1. Open Finder
  2. Press ⌘⇧G
  3. Go to /System/Library/CoreServices/Menu Extras/TimeMachine.menu/Contents/Resources
  4. Replace the four TM*.pdf files with the ones found in this ZIP
@fregante
fregante / pop-out.js
Created December 17, 2014 09:15
Bookmarklet: Pop out the current window in a small, "mobile" window
javascript:window.open(document.location.href,''+Math.random(),'width=320,height=480,top='+(screen.height/2-480/2+Math.random()*100-50)+', left='+(screen.width/2-320/2+Math.random()*100-50))
@fregante
fregante / VH-units-setter.js
Created November 22, 2014 08:41
Fix Android variable VH units (when the browser's bar disappears vh change)
$(function () {
var $els;
var updateHeight = function () {
$els.css('height', ''); // reset previously-set height
$els.height($els.height());// set the current height in px
};
if (/android/i.test(navigator.userAgent)) {
$els = $('ELEMENTS-WITH-VH-UNITS');
updateHeight();//set instantly
$(window).on('orientationchange.vh-height-set', updateHeight);
@fregante
fregante / README.md
Last active August 29, 2015 14:10
Simple HTML5 forms cross-browser validation (UMD)

bfr Form Validation

Make HTML5 form validation cross-browser and with custom callbacks.

Usage

Create an HTML form with the correct attributes to enable the HTML Form validation (type, pattern and required) and then call bfrFormValidation.setup on the form(s) that need to be validated.

The three callbacks, if specified, will be called when validation is not met or met again.

@fregante
fregante / README.md
Last active March 28, 2019 04:26
OS X connection monitor

Connection monitor

Note: if you need a simple connection icon, check out BitBar and its internet checker plugin.

This program notifies you when Internet goes down and when it comes back up.

It pings Google's DNS every 4 seconds; when a ping fails it quickly tries a few more times and switches to downtime mode. When Internet is available again, the cycle restarts.

Tools used

@fregante
fregante / slideshow.scss
Last active August 29, 2015 14:04
Automatic SCSS slideshow used on masseriagialli.it's homepage
$images-count: 4;
$slideshow-duration: 6;
$slideshow-percentage-per-slide: 100/$images-count;
$slideshow-slides-overlap: $slideshow-duration/($images-count+1)+1;
.slideshow {
overflow: hidden;
position: relative;
height: 400px;
z-index: 0;
background-color: $color-golden;