Skip to content

Instantly share code, notes, and snippets.

View bjrnqprs's full-sized avatar

Björn Kuipers bjrnqprs

View GitHub Profile
@bjrnqprs
bjrnqprs / get-url-parameter.js
Created November 15, 2013 10:12
Return the given GET parameter, or null if not found.
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
/**
* Send data to the given URL via a POST request. Or GET if specified.
*
* Origially from Rakesh Pai & Yuck: http://stackoverflow.com/a/133997/440643
*
* @param string path
* @param object params
* @param string method
*/
function postToURL(path, params, method) {
@bjrnqprs
bjrnqprs / resolveUrl.phpsh
Created September 7, 2013 15:43
A simple function to resolve a shortened url to its original. Uses PHP+cURL.
#! /usr/bin/env php
<?php
// Resolve Short URL
function resolveShortURL($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
$yy = curl_exec($ch);
$endUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
@bjrnqprs
bjrnqprs / multi-lang-domain.php
Created August 27, 2013 11:46
Default RealUrl configuration. Might expand this later.
<?php
/**
* Setup multi-language/domain config
*
* NOTE: Multiple domains for a single language will not work.
* The first defined domain is used in that case.
*/
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DOMAINS'] = array(
'encode' => array(
@bjrnqprs
bjrnqprs / devicon.userscript.js
Created July 21, 2013 07:48
A userscript for TamperMonkey. All urls starting with dev. or ending in .dev will have a changed favicon. Slightly altered version of http://userscripts.org/scripts/show/42247. Icon from: http://www.favicon.cc/?action=icon&file_id=350544
// ==UserScript==
// @name Replace favicon for your development sites
// @namespace http://itinko.nl/
// @version 1.0
// @description All urls starting with dev. or ending in .dev will have a changed favicon. Slightly altered version of http://userscripts.org/scripts/show/42247. Icon from: http://www.favicon.cc/?action=icon&file_id=350544
// @match http://*.dev/*
// @match http://dev.*/*
// @copyright 2013+, Björn Kuipers
// ==/UserScript==
@bjrnqprs
bjrnqprs / jquery.getObjectLength.js
Created July 20, 2013 14:22
jQuery function to retrieve the size of an object.
jQuery.extend({
getObjectLength: function(obj){
var length = 0;
if(typeof obj == 'object') {
if(Object.keys) {
length = Object.keys(obj).length;
} else {
var i;
@bjrnqprs
bjrnqprs / gist:5868920
Last active December 19, 2015 00:29
Extend Typeahead (Twitter Bootstrap) with an onshow function. When initializing Typeahead, allows for defining onshow: function() {}.
(function($) {
if($.fn.typeahead != 'undefined') {
var _show = $.fn.typeahead.Constructor.prototype.show;
$.fn.typeahead.Constructor.prototype.show = function() {
if(typeof this.options.onshow == 'function') {
this.options.onshow();
}
// Call parent
// Source: http://stackoverflow.com/a/14823315/440643
var _show = $.fn.modal.Constructor.prototype.show;
$.fn.modal.Constructor.prototype.show = function() {
_show.apply(this, arguments);
//Do custom stuff here
};
@bjrnqprs
bjrnqprs / CmdNameCommandController.php
Created June 11, 2013 13:50
Typo3 6 + ExtBase: Way to create scheduler tasks using namespace's and Extbase's CommandController.
<?php
namespace VENDOR\ExtName\Command;
class CmdNameCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
public function fooCommand($bar) {
echo "foo\n";
}
}
@bjrnqprs
bjrnqprs / gist:5755846
Last active January 29, 2016 13:43
str_replace function with limit
<?php
/**
* Function for performing replaces on strings that allows for the specification of a limit
* on the number of occurrences of $search to replace.
*
* @see http://www.php.net/manual/en/function.str-replace.php#108239
*
* @param $search
* @param $replace