Skip to content

Instantly share code, notes, and snippets.

@oslego
oslego / recursive_toLargestUnit.js
Created December 31, 2016 16:01
Get size on disk by highest order of magnitude using recursion.
// From https://ponyfoo.com/articles/var-let-const
function toLargestUnit (value, unit = `MB`) {
const units = [`MB`, `GB`, `TB`]
const i = units.indexOf(unit)
const nextUnit = units[i + 1]
if (value >= 1024 && nextUnit) {
return toLargestUnit(value / 1024, nextUnit)
}
return { value, unit }
}
@oslego
oslego / pr.md
Created June 11, 2016 12:50 — forked from bgrins/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@oslego
oslego / alternative_switch.js
Created January 20, 2016 15:30
Alternative JS solution to `switch` statement or suite of `if` statements.
/*
Alternative solution to switch statement or a suite of if statements
using an object literal in JS to store cases.
if (type == "save") { }
if (type == "delete") { }
*/
function operation(type, opts) {
var handler = {

JavaScript library to help working with CSS Regions. Handles prefixes internally.

API

flow = Flow('flow-name') Get the NamedFlow by name.

flow.fitWith('<div class="region">') Make the flow fit by adding elements to the region chain

[Draft] Working with CSS Regions, Good Practices

CSS Regions are now enabled by default in a widely used browser - Safari on iOS 7. This makes it easier for developers to experiment and use the feature in their projects.

Perhaps this is a good time to share some of the lessons we learned at Adobe while using CSS Regions in demos. Take this article as a recommendation of good practices, not by any means a comprehensive list. CSS Regions is still an evolving feature.

Use columns sensibly

@oslego
oslego / css-feature-detect.js
Last active December 23, 2015 11:29
Feather-weight CSS feature detect script that adds class names to the <body> element to signal support.
(function(){
// feather-weight Modernizr-like CSS feature check
['shape-inside','flow-into','shiny-new-feature'].forEach(function(property){
// check if any variant exists, prefixed or not
var isCapable = ['-webkit-','-ms-','-moz-',''].some(function(prefix){
return prefix + property in document.body.style
})
property = isCapable ? property : 'no-' + property;
@oslego
oslego / detective.md
Created September 18, 2013 15:36
Outline for 'Detective' web service

Detective

No user left in the dark!

The 'Detective' web service provides a simple way for web developers to add feature detection to their demos that use cutting edge features. It the user's browser does not support a feature, a custom-defined message will inform the user what is to be done.

API

@oslego
oslego / devtools-selected-element.md
Last active December 19, 2015 10:49
How to build a Google Chrome DevTools extension where content scripts can access the node selected in the 'Elements' panel.

[Writting in progress] Chrome Developer Tools extensions and The Selected Element

This article is about building extensions for Google Chrome Developer Tools, also known as Chrome DevTools. Specifically, you'll learn how to work with element that is currently selected in the 'Elements' panel. Prior knowledge about DevTools extensions is required. Check out Boris Smus's Extending Chrome Developer Tools for an introduction and read through Google's own documentation on Chrome Extensions.

Chrome Extensions and Chrome DevTools Extensions

You can build extensions for the Google Chrome browser itself, which are targeted at regular users, as well as extensions for Chrome DevTools - the set of panels that developers use to inspect and audit content on web pages.

@oslego
oslego / convertPixelPathToEm.js
Last active December 19, 2015 08:38
Convert a CSS Shape polygon path from pixels to ems
function convertPixelPathToEm(path){
return path.trim().split(/,\s?/).map(function(pair){
return pair.trim().split(/\s+/).map(function(value){
value = parseInt(value, 10);
value = (value === 0) ? 0 : (value / 16).toFixed(2)
return value + 'em'
}).join(' ')
}).join(', ')
}
@oslego
oslego / stackOnTop.js
Created June 24, 2013 12:43
Forcefully stack an element on top by assigning it the highest z-Index possible.
/*
Make sure the input element is the highest one in the page by z-index
@param {DOM Element} el Element to stack at the top
@param {DOM Element} ref BoundingClientRect reference of where to compare topl-left corner
*/
function stackOnTop(el, ref){
// elementFromPoint returns null if element is outside visible viewport
// scroll the page so the element comes into view
if (window.innerHeight < ref.top){