Skip to content

Instantly share code, notes, and snippets.

View arnorhs's full-sized avatar

arnorhs arnorhs

View GitHub Profile
@arnorhs
arnorhs / bookmarklet-version
Created December 11, 2011 08:28
A simple snippet you can add to your bookmark bar (insert javascript: in front) to measure rendering performance of a state of a webpage
javascript:(function (window,$,runs) { var t = new Date(), i = 1, timetaken,offset = $(window).scrollTop(); $(window).bind('scroll.scrolltest',function () { if (i >= runs) { timetaken = (new Date) - t; console.log('Time taken for '+runs+' scrolls: ',timetaken,' - time per scroll: ', timetaken/runs); $(window).unbind('scroll.scrolltest'); return; } i++; doScroll(); }); function mod (x,y) { return Math.round((x/y - Math.floor(x/y)) *2); } function doScroll () { setTimeout(function(){ $(window).scrollTop(offset + mod(i,2)*100); },0); } doScroll(); })(window,jQuery,500);
@arnorhs
arnorhs / gist:1509904
Created December 22, 2011 10:53
gitopen - Open all files from a git diff or show command
#!/bin/bash
# This script will open all files from a git diff or a git show in vim.
# My bash skills are a bit primitive so this can probably be done more intelligently
# Usage:
# gitopen -- opens all added files that have changed since HEAD
# gitopen diff HEAD -- these are the default parameters
# gitopen diff master -- opens files that have changed from master
@arnorhs
arnorhs / gist:1517095
Created December 24, 2011 10:40 — forked from tessro/gist:1515117
gitopen - Open all files from a git diff or show command
#!/bin/bash
# This script will open all files from a git diff or a git show in vim.
# My bash skills are a bit primitive so this can probably be done more intelligently
# Usage:
# gitopen -- opens all added files that have changed since HEAD
# gitopen diff HEAD -- these are the default parameters
# gitopen diff master -- opens files that have changed from master
@arnorhs
arnorhs / scroll.js
Created May 17, 2012 08:13 — forked from acrookston/scroll.js
Small scrolling script for fun. Not sure how well it works. Please contribute if you have ideas.
// muhaha.. changed all the code
// maybe this version handles scrolling to the bottom edge of a document a little better
// still not satisfied with the speed variable.. should that be higher == more speed, perhaps? or pixels per second?
// sorry about the opinionated style changes
Scrolling = {
smoothScrollTo: function(target_top) {
// ensure that we never scroll further than viewport size from bottom of the doc
target_top = Math.min(target_top, Math.max($(document).height(), $(window).height()) - $(window).height());
var speed = 30,
@arnorhs
arnorhs / LICENSE.txt
Last active December 15, 2015 13:39 — forked from 140bytes/LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@arnorhs
arnorhs / LICENSE.txt
Last active December 15, 2015 15:09 — forked from 140bytes/LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Arnor Sigurdsson <arnorhs@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@arnorhs
arnorhs / gist:5407868
Created April 17, 2013 21:21
Rename a bunch of pngs to <number>.png
i=0; for filename in *; do mv $filename $i.png; ((i++)); done;
@arnorhs
arnorhs / reset.styl
Created December 7, 2013 19:49
"Industry standard" Mayer reset.css ported to stylus. Original: http://www.cssreset.com/scripts/eric-meyer-reset-css/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video
margin: 0
padding: 0
border: 0
outline: 0
font-size: 100%
font: inherit
vertical-align: baseline
body
@arnorhs
arnorhs / dom-utils.js
Created March 2, 2016 13:59
random DOM utility functions
/**
* Given a Node. Find the first parent node that matches a selector
*
* @param node {Node} the base node who's parents will be traversed
* @param selector {string} asdfasdf
* @returns {Node|null} the node, or null if nothing was found
*/
function findFirstParentNodeMatchingSelector(node, selector) {
var parent = node.parentNode;
function islCompare() {
var order = '0123456789aAáÁbBcCdDeEéÉfFgGhHiIíÍjJkKlLmMnNoOóÓpPqQrRsStTuUúÚvVwWxXyYýÝzZþÞæÆöÖ';
function charOrder(a) {
var ix = order.indexOf(a);
return ix === -1 ? a.codePointAt() + order.length : ix;
}
return function(a, b) {
for (var i = 0; i < Math.min(a.length, b.length); i++) {