Skip to content

Instantly share code, notes, and snippets.

View joecritch's full-sized avatar

Joe Critchley joecritch

View GitHub Profile
// Helper classes
$.fn.changeClass = function(className, add) {
add = add || false;
return this.each(function() {
if(add) {
$(this).addClass(className);
}
else {
$(this).removeClass(className);
$('.toggler').bind('change', function() {
var showIt = !$(this).is(':checked');
var panel = $(this).closest('.field').nextAll('.hide');
panel.changeVisibility(showIt)
.closest('fieldset').changeClass('featured', showIt);
});
<!DOCTYPE html "⌘">
<html>
<meta charset=utf-8>
<title>Brap.</title>
<style>
* { margin: 0; padding: 0; }
/** etc **/
</style>
<body>
@joecritch
joecritch / gist:1476393
Created December 14, 2011 12:30
Basic auth middleware for Node.js Express
function basic_auth (req, res, next) {
if (req.headers.authorization && req.headers.authorization.search('Basic ') === 0) {
// fetch login and password
if (new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString() == 'usernamehere123:passwordhere123') {
next();
return;
}
}
console.log('Unable to authenticate user');
console.log(req.headers.authorization);
@joecritch
joecritch / gist:1723442
Created February 2, 2012 13:21
Git add & commit shortcut
git config --global alias.ac '! git add -A && git commit -m'
.class {
background: rgba(255,255,255,0.8);
html.no-rgba & {
background: #eee;
}
}
/** Which would output as: **/
.class { background: rgba(255,255,255,0.8);
.transition (@property: all, @duration: 0.6s, @delay: 0s) {
-webkit-transition: @property @duration ease @delay;
-moz-transition: @property @duration ease @delay;
-ms-transition: @property @duration ease @delay;
-o-transition: @property @duration ease @delay;
transition: @property @duration ease @delay;
}
/* Long-hand for overriding properties */
.transition-property (@property) {
form {
&.filtered {
opacity: 0.5;
}
// ----
.field {
float: left;
&.selected {
background: yellow;
// ---
// Tabs
@mixin round-out-tab($active_class: current, $radius: 8px, $tab_color: $purple, $outer_color: #fff) {
position: relative;
a {
@extend .btn;
}
&.#{$active_class} {
&:before,
&:after {
@joecritch
joecritch / gist:3841065
Created October 5, 2012 17:11
Show hidden images temporarily if sharing to Pinterest (using AddThis)
// Don't forget to include AddThis.
// It's actually really good now so you should be using it.
$images = [ ]; // Or wherever your hidden images are.
// Show images temporarily if sharing to Pinterest
// (Because Pinterest won't see the backgrounds.)
if(typeof addthis !== 'undefined') {
addthis.addEventListener('addthis.menu.share', function(e) {
if (e.type == 'addthis.menu.share' && e.data.service === "pinterest_share") {