Skip to content

Instantly share code, notes, and snippets.

View guilhermesimoes's full-sized avatar
😎

Guilherme Simoes guilhermesimoes

😎
View GitHub Profile
@guilhermesimoes
guilhermesimoes / gist:4595862
Last active December 11, 2015 11:48
Never remove CSS outlines

Quick Tip: Never remove CSS outlines

(Description) Removing CSS outlines without proper fallbacks can make it impossible to navigate your site with a keyboard.

Use of the rule :focus { outline: none; } results in the link or control being focusable but with no visible indication of focus for keyboard users. Even worse, methods to remove it such as onfocus="blur()" result in keyboard users being unable to interact with the link or control.

If you do not like the default focus outline that is displayed when a user clicks on an interactive element, you have 3 accessible solutions:

  1. Style the outline. Webkit browsers have a more prominent outline so you could try styling it to make it less obtrusive. Consider the use of a:focus { outline: thin dotted; } to normalize the look of the outline across browsers.
@guilhermesimoes
guilhermesimoes / index.html
Last active September 5, 2022 21:04
D3.js: Animating Stacked-to-Grouped Bars
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.stacked-chart-container {
position: relative;
}
@guilhermesimoes
guilhermesimoes / line_count_benchmark.rb
Last active September 11, 2023 09:36
Ruby Benchmark: Counting the number of lines of a file
# gem install benchmark-ips
require "benchmark/ips"
path = "lib/rubycritic/cli/options.rb"
Benchmark.ips do |x|
x.report("read + each_line") { File.read(path).each_line.count }
x.report("open + each_line") { File.open(path, "r").each_line.count }
@guilhermesimoes
guilhermesimoes / airbus_data.tsv
Last active September 26, 2019 14:57 — forked from atmccann/airbus_data.tsv
D3.js: Synchronously animating multiple paths in a multi-series line chart
date Airbus Boeing
2000-07-31 0 0
2000-08-31 -0.884 9.8912
2000-09-29 9.6685 32.1383
2000-10-31 32.5967 38.9245
2000-11-30 33.1492 41.4853
2000-12-29 30.7182 35.2113
2001-01-31 27.0718 19.8464
2001-02-28 24.3094 27.4264
2001-03-30 16.0773 14.1306
@guilhermesimoes
guilhermesimoes / README.md
Last active April 6, 2020 23:41
D3.js: Animating bars "going down"

One confusing aspect of animating bars (and working with SVG in general) is that the coordinate system origin is at the top-left corner, which means that y increases downwards.

One would expect that to animate a bar diminishing in size ("going down") changing the height attribute would be all that's needed. However that's not true. This is a visual explanation of why it's necessary to animate both y and height attributes.

Another solution would be to surround the bar with a clipPath element and then transition the bar down. This way, everything on the inside of the clipping area is allowed to show through but everything on the outside is masked out.

This other approach would only work for a simple bar chart though. For a more complex, animated stacked chart, animating both y and height attributes is the only solution.

@guilhermesimoes
guilhermesimoes / README.md
Last active March 27, 2016 23:02 — forked from anonymous/gist:3267597
JScript: Find broken iTunes tracks

JScript to find broken tracks that iTunes can no longer find. Perfect for those who like to manage their large music libraries.

@guilhermesimoes
guilhermesimoes / README.md
Last active April 5, 2020 16:55
D3.js: Animating between scales

The purpose of this gist is two-fold:

  1. Demonstrate how to animate between scales;

  2. Show how data visualization depends on the chosen scale.

    For example, we can see how some data clusters using the power scale. The datums 1 and 10 are rendered on the same spot. If we had a lot of these points close to each other and performance was a concern, filtering out some of these points could prove valuable.

@guilhermesimoes
guilhermesimoes / README.md
Last active October 18, 2015 15:07
JScript: Find small album covers

JScript to find album covers that measure less than 1000x1000 px. Perfect for those who like to manage their large music libraries.

@guilhermesimoes
guilhermesimoes / README.md
Last active September 10, 2023 13:12
YouTube's new morphing play/pause SVG icon

As soon as I saw the new YouTube Player and its new morphing play/pause button, I wanted to understand how it was made and replicate it myself.

From my analysis it looks like YouTube is using [SMIL animations][1]. I could not get those animations to work on browsers other than Chrome and it appears [that they are deprecated and will be removed][2]. I settled for the following technique:

  1. Define the icon path elements inside a defs element so that they are not drawn.

  2. Draw one icon by defining a use element whose xlink:href attribute points to one of the paths defined in the previous step. Simply [changing this attribute to point to the other icon is enough to swap them out][3], but this switch is not animated. To do that,

  3. Replace the use with the actual path when the page is loaded.

@guilhermesimoes
guilhermesimoes / detect-private-browsing.js
Created December 12, 2015 02:57 — forked from cou929/detect-private-browsing.js
Detect private browsing mode (InPrivate Browsing or Incognito).
function retry(isDone, next) {
var current_trial = 0, max_retry = 50, interval = 10, is_timeout = false;
var id = window.setInterval(
function() {
if (isDone()) {
window.clearInterval(id);
next(is_timeout);
}
if (current_trial++ > max_retry) {
window.clearInterval(id);