Skip to content

Instantly share code, notes, and snippets.

View marcus-at-localhost's full-sized avatar
💭

Marcus marcus-at-localhost

💭
View GitHub Profile
@marcus-at-localhost
marcus-at-localhost / requestCrossDomain.js
Created August 26, 2012 08:43
Crossdomain JSONP request via YQL
var url_str = 'http://www.google.com/ig/api?weather=Berlin+Germany&hl=de';
requestCrossDomain(url_str, function(json) {
// check the real output at YQL console
// http://goo.gl/Z9XHu
console.log(json.xml_api_reply.weather)
});
// Accepts a url and a callback function to run.
// returns jsonp
@marcus-at-localhost
marcus-at-localhost / reveal-map-inbootstrap-tab.js
Last active November 7, 2017 19:24
[Bootstrap Tabs reveal $.goMap] google map with a glitch. trigger resize didn't work, so I had to set showing the tab with display:block before rendering the map. maybe the css transition delays it?! anyway here is the fiddle:http://jsfiddle.net/8kdpY/2/
$('a[data-toggle="tab"]').on('show', function (e) {
var $target = $(e.target.hash);
var h = e.target.hash.indexOf('map-');
if(h != -1 ){
var loc = $target.parents('.tab-content').find('address').data('address');
var id = $target.find('.google-maps').attr('id');
/* set the active class here, because the map init doesn't wait for the .fade.in
css trasition from bootstrap
*/
@marcus-at-localhost
marcus-at-localhost / languagefilter.php
Created March 18, 2014 19:30
Joomla Language 303 redirect to better 301 redirect (/plugins/system/languagefilter/languagefilter.php)
// redirect if sef does not exists
// around line 226
if (!isset(self::$sefs[$sef]))
{
// Use the current language sef or the default one
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setPath($sef . '/' . $path);
if ($app->getCfg('sef_rewrite')) {
// append true for 301 redirect
@marcus-at-localhost
marcus-at-localhost / EasyWsdl2PHP.php
Created March 29, 2014 20:57
*EASY WSDL2PHP* generates the objects and function calls from your WSDL https://sourceforge.net/projects/easywsdl2php/
<?php
class EasyWsdl2PHP
{
static public function generate($url,$sname)
{
$soapClient = new SoapClient($url);
$classesArr = array();
$functions = $soapClient->__getFunctions();
@marcus-at-localhost
marcus-at-localhost / col.html
Last active August 29, 2015 13:58
Bootstrap flexbox widgets via http://www.bootply.com/126437 by @carolskelly
<div class="container"><h3>.row-flex (make columns equal heights in each row)</h3></div>
<div class="container">
<div class="row row-flex row-flex-wrap">
<div class="col-md-3">
<div class="panel panel-default flex-col">
<div class="panel-heading">Title flex-col</div>
<div class="panel-body flex-grow">Content here -- div with .flex-grow</div>
<div class="panel-footer">Footer</div>
</div>
</div>
@marcus-at-localhost
marcus-at-localhost / bench.php
Created August 28, 2014 10:23
jsperf.com like script to benchmark php functions
<?php
// jsperf.com like script to benchmark php functions.
// http://baylorrae.com/blog/2012/01/09/benchmarking-php-script-speeds/
// a place to store the result of each test
$results = array();
// my version of un-camel casing a word
function test_1() {
return strtolower(implode(' ', preg_split('/(?<=\\w)([A-Z])/', 'aCamelCasedWord')));
@marcus-at-localhost
marcus-at-localhost / delivery_date.php
Last active November 13, 2022 13:07
Delivery date calculation - ship till a certain time, add n days for delivery and detect weekends DateTime Class in PHP
<?php
// new date/time object
$date = new DateTime('now');
// set order time to a Saturday, 2 pm
$date->modify('next sat 14:00');
// orders are taken in till 15 minutes before 2pm
// http://php.net/manual/de/datetime.formats.relative.php
$order_till = new DateTime('front of 14');
@marcus-at-localhost
marcus-at-localhost / css_select_by_position.js
Created February 3, 2015 20:55
jquery select by position
// http://stackoverflow.com/a/9769532/814031
$('*').filter(function(){
var position = $(this).css('position');
return position === 'absolute';
});
// or extend jquery selector engine
// http://stackoverflow.com/a/9770766/814031
$.extend($.expr[':'],{
absolute: function(el) {
@marcus-at-localhost
marcus-at-localhost / feiertage.class.php
Last active February 7, 2018 10:46
Simple German holidays helper class with DateTime Class (Deutsche Feiertage)
<?php
class Holidays
{
public static function getEaster()
{
$easter = new DateTime('now');
$year = $easter->format('Y');
$easter->setDate($year, 3, 21);
$easter->setTime(0, 0, 0);
@marcus-at-localhost
marcus-at-localhost / Partial-string-replacement.php
Last active August 29, 2015 14:21
Partial string replacement to anonymize credit card numbers, bank account numbers etc
/**
* Replace middle of the string with given char, keeping length
* http://mamchenkov.net/wordpress/2011/05/17/partial-string-replacement-with-fixed-length-in-php/
*
* <code>
* print padString('1234567890123456', 1, 4, 'x');
* </code>
*
* @param string $string String to process
* @param integer $start Characters to skip from start