Skip to content

Instantly share code, notes, and snippets.

@zanona
zanona / getStyle.js
Created April 28, 2011 10:28 — forked from cms/getStyle.js
Get computed styles
function getStyle(el, styleProp) {
var value, defaultView = el.ownerDocument.defaultView;
// W3C standard way:
if (defaultView && defaultView.getComputedStyle) {
// sanitize property name to css notation (hypen separated words eg. font-Size)
styleProp = styleProp.replace(/([A-Z])/g, "-$1").toLowerCase();
return defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
} else if (el.currentStyle) { // IE
// sanitize property name to camelCase
styleProp = styleProp.replace(/\-(\w)/g, function(str, letter) {
@zanona
zanona / javascriptgrid.js
Created August 18, 2011 13:44
Implementation of http://javascriptgrid.org/ toggling with keystroke `g` by default
function grid() {
var k, d, e, g, j, a, m, h, l, c, o, n, b, f;
c = {
columns: {
"default": {
columns: 12
}
},
gapWidth: 20,
@zanona
zanona / cloneObj.js
Created November 14, 2011 12:08
JS action for cloning object and send a filter param altogether
function clone(origin, filter) {
'use strict';
var obj, p;
function isTypeOf(obj) {
if (obj === undefined) { return undefined; }
var obType = String(obj.constructor).match(/function\s+(\w+)/);
return obType ? obType[1] : 'undefined';
//return obType ? (obType[1] === type) : false;
}
@zanona
zanona / parseFloats.js
Created November 10, 2012 16:52
Parse any float number from within a provided text.
function parseFloats(str) {
/*jslint regexp:true*/
str = (str || '').replace(/[\x80-\xFF]|&.{0,}?;/g, '') || '';
var m = str.match(/[0-9]{1,}(\.|,)?([0-9]{1,})?(\.|,)?([0-9]{1,})?/g) || [];
m = m.map(function (item) {
item = item.match(/(\d+)((,|\.)(?!.*(,|\.)[0-9]))?/g).join('').replace(/\.|,/, '.');
return parseFloat(item, 10);
});
@zanona
zanona / svg.retina.html
Last active December 21, 2015 01:48
SVG Pixel Density Test for retina enabled displays. Note how mask and clipPath are raster based instead vector.
<!doctype html>
<title>Document</title>
<meta charset='utf-8'>
<style>
body {
min-height: 1800px;
background: #EFEFEF;
}
.container {
position: relative;
### Keybase proof
I hereby claim:
* I am zanona on github.
* I am zanona (https://keybase.io/zanona) on keybase.
* I have a public key whose fingerprint is B7F8 DA33 FCA5 FB13 C31F 120B B8BB 359D BF0A 62FC
To claim this, I am signing this object:
@zanona
zanona / git.md
Last active April 10, 2019 08:37
DevTips

Git Tips

Mirror local repo to reflect remote

git fetch origin
git reset --hard origin/master

Delete remote branch

@zanona
zanona / dom-loading.md
Created March 6, 2015 12:05
DOM Loading event triggering and ready state order

DOM Loading event triggering and ready state order

On document

(head or body have same behaviour)

  • inline/src
    • runtime - loading
    • onreadystatechange - interactive
  • DOMContentLoaded - interactive
@zanona
zanona / swagger-linter.js
Created March 2, 2016 17:10
Swagger Linter outputting line and column numbers
/*jslint node:true, stupid:true*/
module.exports = function (src) {
'use strict';
src = require('path').resolve(src);
var tapi = require('sway'),
YAML = require('yaml-js'),
fs = require('fs'),
file = fs.readFileSync(src).toString();
function positionRangeForPath(yaml, path, cb) {
@zanona
zanona / nodelist-iteration.js
Created May 20, 2016 12:18 — forked from bendc/nodelist-iteration.js
ES6: Iterating over a NodeList
var elements = document.querySelectorAll("div"),
callback = (el) => { console.log(el); };
// Spread operator
[...elements].forEach(callback);
// Array.from()
Array.from(elements).forEach(callback);
// for...of statement