Skip to content

Instantly share code, notes, and snippets.

View barneycarroll's full-sized avatar
🛠️
Working on Mithril type stuff

Barney Carroll barneycarroll

🛠️
Working on Mithril type stuff
View GitHub Profile
@barneycarroll
barneycarroll / jquery.selectable.js
Last active October 11, 2015 03:17
Turn selectability on or off via jQuery
// Selectability: pass true or false
// http://stackoverflow.com/questions/2700000/how-to-disable-text-selection-using-jquery
$.fn.selectable = (function _selectable(){
var values = [
// Off
['on', 'none', false],
// On
['off','text', $.noop]
];
@barneycarroll
barneycarroll / Preferences.sublime-settings
Created October 29, 2012 10:29
Sublime Text settings JSON
{
"ensure_newline_at_eof_on_save": true,
"font_size" : 10,
"tab_size" : 2
}
@barneycarroll
barneycarroll / dabblet.css
Created November 27, 2012 14:45
Fixing shitty WebKit text rendering for thin and quirky fonts
/**
* Fixing shitty WebKit text rendering for thin and quirky fonts
*/
html {
font-family: 'Quicksand';
font-size: 24px;
padding: 1em 5em;
-webkit-text-stroke-width: .25px;}
@barneycarroll
barneycarroll / utilities.js
Last active December 14, 2015 02:19
Quick and dirty methods for object cloning and comparison using the JSON parser
// Create a copy of x without reference back to x
function clone(x){
return JSON.parse(JSON.stringify(x));
}
// Pass any number of arguments of non-function type. Returns true if they are all identical.
function areEqual(){
for(var i = 1, l = arguments.length, x = JSON.stringify(arguments[0]); i < arguments.length; ++i){
if(x !== JSON.stringify(arguments[i])){
return false;
@barneycarroll
barneycarroll / ieVersion.js
Last active December 14, 2015 22:39
Get your /h5bp/-like HTML classnames for IE versions dynamically. Useful if you don't have control of the raw markup as spat out by the server.
// Optain classnames representing the IE rendering engine:
// Makes version-targetted CSS much cleaner
var sIEclass = (function determineIEversion(){
// A DOM element to run the test on
var oTest = document.createElement('test');
// A table matching tested versions to representative class string
var hVersions = {
"6" : "ie ltie10 ltie9 ltie8 ltie7 ie6",
"7" : "ie ltie10 ltie9 ltie8 ie7",
"8" : "ie ltie10 ltie9 ie8",
@barneycarroll
barneycarroll / fileInput.css
Last active April 2, 2023 22:21
Total input[type=file] style control with pure CSS. File type inputs are notoriously hard to style, due to different semi-serious style restrictions in the name of security (the argument being that a file input presents access to the user's private file system, and should as such always look unambiguously like what it is — redundant if you ask m…
.fileContainer {
overflow: hidden;
position: relative;
}
.fileContainer [type=file] {
cursor: inherit;
display: block;
font-size: 999px;
filter: alpha(opacity=0);
@barneycarroll
barneycarroll / mediaJQuery.css
Created March 26, 2013 12:52
Javascript to emulate media queries with event firing and HTML class toggling to avoid duplication, conflict & waste in native CSS implementation + JS feature dependency. Public version of a private gist created 2012-09-13T11:34:06Z
/* Javascript to emulate media queries with events and HTML class toggling
* to avoid duplication, conflict & waste when implemented via
* native CSS implementation + JS feature dependency.
*
* Depends on jQuery and Cowboy's throttle / debounce plugin:
* https://github.com/cowboy/jquery-throttle-debounce
*/
(function(){
var options = {
@barneycarroll
barneycarroll / jquery.getLines.js
Last active December 29, 2015 02:51
Count the number of lines of text in a given element.
void function $getLines($){
function countLines($element){
var lines = 0;
var greatestOffset = void 0;
$element.find('character').each(function(){
if(!greatestOffset || this.offsetTop > greatestOffset){
greatestOffset = this.offsetTop;
++lines;
}
@barneycarroll
barneycarroll / Location.es6.min.js
Last active August 24, 2018 09:36
An ultra-small URI parsing function that accepts a URI-like string & returns an object with all the string properties of the native Location object for that string. Works using native property detection, without received wisdom (ie dictionaries, inference, etc).
export default x=>document.createElement('a').href=x
@barneycarroll
barneycarroll / later.js
Last active December 16, 2015 08:09
`setTimeout(fn, 0)` is a hack to defer calling `fn` til the synchronous stack has executed, and has many very useful applications — but there's a bit of cognitive overhead in ascertaining that `setTimeout` isn't being used as per its intended use case: this flummoxes novices especially, who may interpret this as a mistake. Is it worth abstractin…
// functions passed to later will only execute once the stack has resolved.
function later(fn){
return setTimeout(fn,0);
}
void function executionScope(){
var x = 0;
console.log('Log 1: ' + x);