Skip to content

Instantly share code, notes, and snippets.

View bjrnqprs's full-sized avatar

Björn Kuipers bjrnqprs

View GitHub Profile
<?php
/**
* Clears the cache based on the command $cacheCmd.
*
* $cacheCmd='pages': Clears cache for all pages. Requires admin-flag to
* be set for BE_USER.
*
* $cacheCmd='all': Clears all cache_tables. This is necessary if
* templates are updated. Requires admin-flag to be set for BE_USER.
*
@bjrnqprs
bjrnqprs / gist:5487083
Last active September 7, 2018 11:25
Typo3 6.0 - Generate a cHash (Note: differs from cache identifier in Extbase caching framework)
<?php
/* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */
$cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator');
$result = $cacheHash->generateForParameters($_SERVER['QUERY_STRING']);
@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
@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";
}
}
// 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 / 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
@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 / 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 / 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 / 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);