Skip to content

Instantly share code, notes, and snippets.

View levvsha's full-sized avatar

Mikhail Shabrikov levvsha

View GitHub Profile
@zspecza
zspecza / stylus-best-practices.md
Last active May 27, 2021 05:25
Stylus Best Practices

Stylus Best Practices

Introduction

This is a curated set of conventions and best practices for Stylus, an expressive, dynamic, robust and advanced CSS preprocessor. Frustrated with there not being a set of conventions set in place (that could be easily found), I set forth to find out on my own.

@miguelmota
miguelmota / endall.js
Last active August 27, 2019 09:23
D3 callback when all transitions are done
function endAll(transition, callback) {
var n = 0
transition.each(() => ++n)
.each('end', () => (!--n && callback.apply(this, arguments)))
}
// Usage
// d3.selectAll('g').transition().call(endAll, allDone)
@ghinda
ghinda / object-to-form-data.js
Last active May 21, 2024 20:48
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@paulirish
paulirish / what-forces-layout.md
Last active July 5, 2024 08:26
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
@peterpham
peterpham / console-happy-birthday.js
Created April 12, 2016 03:27
Create a message Happy Birthday in browser's console
(function(){
var text = "Happy Birthday, Steve!",
length = text.length,
chr = 1,
ar = text.split(),
today = new Date();
try {
if (window.console) {
if (console.clear && console.log) {
if (today.getDate() === 17 && today.getMonth() === 2) {