Skip to content

Instantly share code, notes, and snippets.

View mcbrwr's full-sized avatar

Matthijs Brouwer mcbrwr

View GitHub Profile
@mcbrwr
mcbrwr / iconizr-template.less
Last active August 29, 2015 14:02
iconizr LESS template - not very lean.. but it is full featured
{{#svg}}
{{#selector}}.{{expression}}{{^last}},
{{/last}}{{/selector}} { {{#sprite}}
background-position: {{position}};{{/sprite}}{{^common}}
background-repeat: no-repeat;{{#dimensions}}
display: block;
text-indent: -999em;
width: {{width}}px;
height: {{height}}px;{{/dimensions}}
background-image: url(/assets/sprite/{{#sprite}}{{sprite}}{{/sprite}}{{^sprite}}{{#encode}}"{{encoded}}"{{/encode}}{{^encode}}{{path}}{{/encode}}{{/sprite}});{{/common}}
@mcbrwr
mcbrwr / overlay-video-play-icon.less
Created June 2, 2014 08:42
LESS overlay video play icon
.vidicon(@size) {
@trisize: (@size / 3);
position: relative;
z-index: 1;
&:before,
&:after {
content: "";
opacity: .7;
display: block;
position: absolute;
@mcbrwr
mcbrwr / documentready
Created June 1, 2014 10:00
Do something when the document is ready
var readyStateCheckInterval = setInterval(function() {
if (document.readyState === "complete") {
// do stuff
init();
clearInterval(readyStateCheckInterval);
}
}, 10);
@mcbrwr
mcbrwr / hisrc
Created May 21, 2014 09:24
Dynamicly load hires image based on window width
# hisrc: load low src image by default and on defined breakpoint load hires image
# html markup: <img data-breakpoint="450" data-hisrc="large-image.jpg" src="default-image.jpg" alt=" ">
# data-breakpoint="450" is not needed, 450 is default
hisrc = () ->
window_width = $(window).width()
$('[data-hisrc]').each () ->
$(this).attr('data-breakpoint', '450') if not $(this).attr('data-breakpoint')
$(this).attr('data-losrc', $(this).attr('src') ) if not $(this).attr('data-losrc')
@mcbrwr
mcbrwr / svn-pristine-find.sh
Last active July 8, 2024 09:26
fix for "svn pristine text not present" error in a working copy
#!/bin/bash
# for an "svn pristine text not present" error like this:
# svn: E155010: Pristine text 'd6612ee6af5d9fb4459cbe7e2e8e18f7fb4201f8' not present
# you can delete the file and retrieve it with svn up
# (if you have local modifications, make up your own plan)
# -
# Run this script from the root of the working copy.
# It retrieves the file that's causing the error from wc.db
# usage example : ./svn-pristine-find.sh d6612ee6af5d9fb4459cbe7e2e8e18f7fb4201f8
@mcbrwr
mcbrwr / gist:6477796630c58423be68
Created May 1, 2014 13:28
bash: remove all svn directories from an old repository
rm -rf $(find . |grep .svn| grep -v svn/)
@mcbrwr
mcbrwr / smooth_scroll.coffee
Created April 24, 2014 06:51
Smooth scroll
$("a[href*=#]:not([href=#])").click ->
if location.pathname.replace(/^\//, "") is @pathname.replace(/^\//, "") and location.hostname is @hostname
scrollByClick = true
target = $(@hash)
target = (if target.length then target else $("[name=" + @hash.slice(1) + "]"))
offset_fix = -60
if $(window).scrollTop() < 10
offset_fix = -200
@mcbrwr
mcbrwr / anti-form-spam.js
Last active August 29, 2015 13:57
form spam protection - the easy way
$('form :text').keydown(function(){
if (!$(this).parents('form').children('.pl').length) {
var d = new Date();
var n = d.getDay()*d.getDate();
$(this).parents('form').append('<input type="hidden" name="pl" class="pl" value="'+n+'">');
}
});
@mcbrwr
mcbrwr / isnode_iselement
Created March 15, 2014 07:24
Check if thing is node or dom element
//Returns true if it is a DOM node
function isNode(o){
return (
typeof Node === "object" ? o instanceof Node :
o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string"
);
}
//Returns true if it is a DOM element
function isElement(o){
@mcbrwr
mcbrwr / fallback_svg_to_png.coffee
Last active August 29, 2015 13:56
Replace SVG in all image sources with PNG for browsers that don't support it.
# replace "svg" in all image src's with png for browser without svg support
checkA = document.implementation?.hasFeature "http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"
checkB = document.implementation?.hasFeature "http://www.w3.org/TR/SVG11/feature#Shape", "1.0"
if not checkA and not checkB
for image in document.images
image.src = image.src.replace(/\.svg/i, '.png')