Skip to content

Instantly share code, notes, and snippets.

🤑
Looking for work

Barney Carroll barneycarroll

🤑
Looking for work
Block or report user

Report or block barneycarroll

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@barneycarroll
barneycarroll / README.md
Last active Jun 16, 2019
Lock and unlock a page's scroll position.
View README.md

jquery.scrollLock.js

Useful for when a blocking user experience is needed (in my case, didn't want people unwittingly loosing their place by scrolling while a modal required their attention): $.scrollLock() locks the body in place, preventing scroll until it is unlocked.

// Locks the page if it's currently unlocked
$.scrollLock();

// ...or vice versa
View Refresher.js
import {m} from './deps.js'
import viewOf from './viewOf.js'
// View component exposing a single function:
// Once invoked, the function causes the subtree to be reinitialised
export default () => {
let timestamp
const refresh = () => {
@barneycarroll
barneycarroll / jquery.lipo.js
Last active Mar 23, 2019
Get rid of redundant whitespace & empty structural elements, in that order
View jquery.lipo.js
void function semanticContentScope(context, jQuery){
var $ = context.jQuery || jQuery || false;
if(!$){
return false;
}
// Strips elements of duplicate, leading and trailing whitespace and removes empty non-functional elements recursively
function semanticContent(markup){
// Conversion
@barneycarroll
barneycarroll / tern.es5.js
Last active Feb 14, 2019
A ternary function for convenient conditional expressions (especially in Mithril views, where ternary operators can look confusing).
View tern.es5.js
// Verbose ternary function to add debugging points and make views more legible.
// If `defer` is true and the pass/fail outcome is a function, it will be invoked:
// This allows you to conditionally return expressions which would break execution depending on `condition`
function tern( condition, pass, fail, defer ){
if( !fail ) fail = ''
if( defer && condition instanceof Function ) condition = condition()
var outcome = condition ? pass : fail;
@barneycarroll
barneycarroll / unfuckReact.js
Last active Feb 7, 2019
React components are so fucking stupid, it's unbelievable. 3 months with this library version 15 and the glaring stupidity of the API just keeps coming in waves. Fixing some of this stuff – just for the sake of internal consistency – would have been so simple. The number of hoops you're required to jump through for trivial shit. Ugh.
View unfuckReact.js
const mounted = new WeakSet()
export default const unfucker = (component, displayName = component.displayName || component.name || 'React.Component') => {
const host = {
[displayName] : class extends React.Component {
constructor(){
this.state = {}
component.apply(this, arguments)
}
@barneycarroll
barneycarroll / fileInput.css
Last active Feb 4, 2019
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…
View fileInput.css
.fileContainer {
overflow: hidden;
position: relative;
}
.fileContainer [type=file] {
cursor: inherit;
display: block;
font-size: 999px;
filter: alpha(opacity=0);
@barneycarroll
barneycarroll / dabblet.css
Created Nov 27, 2012
Fixing shitty WebKit text rendering for thin and quirky fonts
View dabblet.css
/**
* 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 / jquery.notextSelector.js
Last active Oct 12, 2018
`:notext` is an alternative to the `:empty` selector for jQuery. Elements consisting exclusively of an amount of whitespace or HTML comments will be returned.
View jquery.notextSelector.js
/*
jQuery's ':empty' selector only returns true if the element contains no text node, or whose text node consists exclusively of zero or more spaces and tabs. This ':notext' selector will return true for elements whose text nodes can also contain line breaks (any whitespace character) and HTML comments.
*/
$.expr[':'].notext = function detectNoText(x){
return x.innerHTML && x.innerHTML.replace(/(<!--.*(?!-->))|\s+/g, '').length === 0
}
@barneycarroll
barneycarroll / Drizzle.md
Created Sep 6, 2018
Drizzle, a short story by Hjalmar Söderberg
View Drizzle.md

Drizzle

Autumn is here again with its dismal days, and the sun is hiding himself in the darkest corner of the heavens so that no one shall see how pale and aged and worn he has grown in this latter time. But while the wind whistles in the window-chinks and the rain purls in the rainspouts and a wet dog howls in front of a closed gate down below on the street and before the fire has burned down in our tile stove, I will tell you a story about the drizzle. Listen now!

For some time back the good God had become so angered over the wickedness of men that he resolved to punish them by making them still wickeder. He should, in his great goodness, have liked above all things to have drowned them all together in a new Deluge: he had not forgotten how agreeable was the sight when all living creatures perished in the flood. But unfortunately in a sentimental moment he had promised Noah never to do so again.

"Harken, my friend I" he therefore said to the Devil one day. "You are assuredly no saint, but occasionall

@barneycarroll
barneycarroll / tabitha.js
Created Oct 10, 2018
Get user-focusable elements within a context in tab order
View tabitha.js
// Source
const tabitha = (context = document) =>
[
...context.querySelectorAll('*')
]
.filter(element => {
const style =
window.getComputedStyle(element)
return (
You can’t perform that action at this time.