Skip to content

Instantly share code, notes, and snippets.

View mcbrwr's full-sized avatar

Matthijs Brouwer mcbrwr

View GitHub Profile
@mcbrwr
mcbrwr / currentHostname
Last active December 12, 2015 00:48
get current hostname in PHP
function currentHostname() {
isset($_SERVER['HTTPS']) ? $pageURL = 'https://' : $pageURL = 'http://';
$pageURL .= $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"] : $_SERVER['SERVER_NAME'];
return $pageURL;
}
function getElementsByClassName(node,classname) {
if (node.getElementsByClassName) {
// use native implementation if available
return node.getElementsByClassName(classname);
} else {
return (function getElementsByClass(searchClass,node) {
if ( node == null )
node = document;
var classElements = [],
els = node.getElementsByTagName("*"),
@mcbrwr
mcbrwr / isFunction
Created October 21, 2013 10:01
check if given argument is a function
function isFunction(functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
}
@mcbrwr
mcbrwr / autogit.sh
Created March 2, 2014 08:44
AutoGit. Monitor a working copy and add/commit/pull/push on file changes. Nice for staging servers, not for production ofcourse..
#!/bin/bash
sha=0
previous_sha=0
commitmsg="online changes (autogit)"
if [ $1 ]; then
repo=$1
else
repo='.'
@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')
@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 / 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 / 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 / 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 / svn-pristine-find.sh
Last active March 9, 2021 03:46
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