Skip to content

Instantly share code, notes, and snippets.

View joshje's full-sized avatar

Josh Emerson joshje

View GitHub Profile
@joshje
joshje / netmag-wordcount.js
Last active August 29, 2015 14:07
Word counter for net magazine article submissions (1 line of code = 10 lines). Uses <pre> tags in the page to determine code blocks.
(function() {
var codeBlocks = document.getElementsByTagName('pre'),
codeLines = 0,
body = document.getElementsByTagName('body')[0],
text = function(el) {
if (el.innerText) return el.innerText;
return el.textContent;
};
var wordCount = text(body).split(' ').length;

Keybase proof

I hereby claim:

  • I am joshje on github.
  • I am joshje (https://keybase.io/joshje) on keybase.
  • I have a public key whose fingerprint is 3224 62D2 9BFD 69ED 9312 2D02 4A47 F6D0 7BB0 495D

To claim this, I am signing this object:

@joshje
joshje / supports.js
Created August 16, 2011 14:35
Cross Browser CSS Selector Support Detection
function supports(prop) {
var div = document.createElement('div'),
vendors = ['Khtml','Ms','O','Moz','Webkit'],
len = vendors.length;
if (prop in div.style) return true;
var prop = prop.replace(/^[a-z]/, function(val) {
return val.toUpperCase();
});
while(len--) {
if ( vendors[len] + prop in div.style ) return true;
@joshje
joshje / base60
Created September 20, 2011 16:23
Base60 Converter
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Base60 Converter</title>
</head>
<body>
<p><label for="n">Number</label><input id="n"> &rarr; <label for="s">Base 60</label><input id="s"></p>
<script>
ni = document.getElementById('n');
@joshje
joshje / async
Created January 10, 2012 01:14
Asyncronously load javascript by passing in a URL
function async(url) {
var a = document.createElement('script');
a.async = true;
a.src = url;
var b = document.getElementsByTagName('script')[0];
b.parentNode.insertBefore(a, b);
}
@joshje
joshje / reveal-titles.js
Created April 30, 2012 17:19
Reveal title attribute within innerHTML of time elements
// Uncompressed:
(function() {
var els = document.querySelectorAll('[title]');
for (var i=0,len=els.length;i<len;++i) {
var el = els[i];
if (el.title!='') {
el.innerHTML+=' <span style="background:#EEE;color:#333;padding:2px;font-weight:normal;font-style:normal">'+el.title+'</span>';
el.removeAttribute('title');
}
}
@joshje
joshje / supportsFFS.html
Created June 21, 2012 11:02
CSS font-feature-settings support detection
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Opentype Test</title>
<style>
span.opentype-test {
font-family: Corbel;
font-size: 100px;
position: absolute;
@joshje
joshje / fontloading.html
Created October 30, 2012 11:36
Load Fontdeck fonts asynchronously with hidden text timeout
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function async(url) {
var a = document.createElement('script');
a.async = true;
a.src = url;
var b = document.getElementsByTagName('script')[0];
@joshje
joshje / ikealist.js
Last active December 19, 2015 15:08
Reveal product codes on IKEA shopping list (http://www.ikea.com/webapp/wcs/stores/servlet/InterestItemDisplay)
(function() {
var l = document.querySelectorAll('.prodInfoContainer a');
for (i=0; i<l.length; i++) {
s = document.createElement('span');
s.innerHTML = l[i].href.replace(/[^0-9]/,'') + '<br>';
l[i].appendChild(s);
}
}();
@joshje
joshje / styles.less
Created July 6, 2016 09:19
Atom editor custom stylesheet
// Make close icons always visible
.tab-bar .tab,
.tab-bar .tab.active {
.title {
padding-right: 20px;
}
.close-icon {
transform: scale(1);