Skip to content

Instantly share code, notes, and snippets.

@davidhellsing
davidhellsing / entity.js
Created September 12, 2011 19:51
Simple bookmarklet to convert selected text to HTML entities
function n(f) {
return f.replace(/</g,"&lt;").replace(/>/g,"&gt;");
}
a = document.activeElement;
v = a.value;
s = a.selectionStart;
e = a.selectionEnd;
a.value = v.substr(0,s) + n(v.substr(s,e)) + v.substr(e,v.length);
/*
@davidhellsing
davidhellsing / support.letterspacing.js
Created January 10, 2012 13:51
Test if browser supports fractional values of letter spacing
/* Test if the browser supports decimal letterspacing for fine kerning (f.ex 0.5px)
* At the moment (january 2012), at least webkit (chrome & safari) does not render decimal pixels correctly
* https://bugs.webkit.org/show_bug.cgi?id=20606
* Using this method, you can at least provide an alternative kerning for those browsers
*/
var letterspacing = (function(d) {
var test = d.createElement('div'),
ret = true;
test.style.letterSpacing = '.5px';
@davidhellsing
davidhellsing / prime.js
Created February 20, 2012 19:16
Prime number tester
// Test if a number is Prime using a simple regex.
// Demo: http://jsfiddle.net/rJhpq/
function prime(n) {
return !/^1?$|^(11+?)\1+$/.test((function(n){s='';while(n--)s+='1';return s;}(n)));
}
iframe.attachEvent && iframe.attachEvent("onload", onload);
iframe.onload = onload;
@davidhellsing
davidhellsing / gist:5669606
Created May 29, 2013 11:24
Detect possibly conflicting or multi-bound events in jQuery
(function($) {
var add = $.event.add;
$.event.add = function() {
var elem = arguments[0],
types = arguments[1];
if ( !types || !elem ) return add.apply(this, arguments);
types = (types || "").match(/\S+/g) || [];
var events = $._data(elem).events;
if ( events && types.length ) {
$.each(types, function(i, type) {
@davidhellsing
davidhellsing / gist:6140433
Last active December 20, 2015 13:39
Animate anything with easing and requestFrame.
Animate = (function() {
var requestFrame = (function(){
var r = 'RequestAnimationFrame'
return window.requestAnimationFrame ||
window['webkit'+r] ||
window['moz'+r] ||
window['o'+r] ||
window['ms'+r] ||
function( callback ) {
@davidhellsing
davidhellsing / gist:7488964
Last active December 28, 2015 10:49
Module prefix
(function(a, i, n, o) {
n = i.length && typeof require == 'function' ? (function(e, j, q) {
q = []
for(j=0; j<i.length; j++){
q.push(require(i[j]))
}
return e.apply(o, q)
}(n)) : n.call(o)
@davidhellsing
davidhellsing / gist:7597680
Created November 22, 2013 10:10
OS X apache - create a local dev directory
$ cd /Library/WebServer
$ sudo -s
$ mv Documents Documents.old
$ sudo ln -s [projpath] .
$ mv [dirname] Documents
# Now just goto http://localhost and see all your local projects
@davidhellsing
davidhellsing / gist:7600706
Created November 22, 2013 14:28
IE detection including IE10+11
var ie = (function() {
var v = 3
, div = document.createElement( 'div' )
, all = div.getElementsByTagName( 'i' )
do
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->'
while
(all[0])
return v > 4 ? v : document.documentMode
}())
@davidhellsing
davidhellsing / gist:8052234
Created December 20, 2013 09:03
Clean git repo: "error: The following untracked working tree files would be overwritten by checkout"
git clean -d -fx ""