Skip to content

Instantly share code, notes, and snippets.

View tistre's full-sized avatar

Tim Strehle tistre

View GitHub Profile
@tistre
tistre / googlemaps_demo.js
Last active February 16, 2017 14:16
Google Maps demo for Tim’s simple JavaScript component test, see https://www.strehle.de/tim/weblog/archives/2014/02/19/1694
/* Namespace */
var DCX = DCX || { };
DCX.Ui = DCX.Ui || { };
DCX.Ui.Model = DCX.Ui.Model || { };
DCX.Ui.View = DCX.Ui.View || { };
DCX.Ui.Controller = DCX.Ui.Controller || { };
DCX.Ui.Service = DCX.Ui.Service || { };
@tistre
tistre / gist:9239838
Last active August 29, 2015 13:56
Bookmarklet to open the dialog for creating a Google Calendar event from a MantisBT issue detail page. Quick & dirty, works for me.
javascript: var title = 'Mantis #' + document.title.substring(2, (document.title.length - 11)); var url = 'https://www.google.com/calendar/render?action=TEMPLATE&sf=true&output=xml&text=' + encodeURIComponent(title) + '&details=' + encodeURIComponent('Details in Mantis: ' + location.href); window.open(url, 'mantisgcal', 'scrollbars=yes,width=1200,height=800,top=175,left=75,status=no,resizable=yes'); if (!document.all) T = (setTimeout('popw.focus()',50)); void(0);
@tistre
tistre / cookies_from_raw_http_response.php
Created April 7, 2014 08:36
Parse cookies from raw HTTP response using PHP’s pecl_http
<?php
$msg = <<<EOT
HTTP/1.1 200 OK
Date: Mon, 07 Apr 2014 08:29:07 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.20
Set-Cookie: dcx_app_trunk=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/dcx_trunk/
Set-Cookie: dcx_app_trunk=33mnkpiau2s80uhrtb7a105l23; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
@tistre
tistre / gist:575ef1f0220097c7a585
Last active August 29, 2015 14:04
jQuery.Deferred(): If an array contains promises, replace them with the real value once resolved
// Usage:
// resolvePromisesInArray(values_with_promises).then(function(values_resolved)
// { console.log(values_resolved); });
function resolvePromisesInArray(values)
{
var deferred, deferred_values;
if (! $.isArray(values))
{
@tistre
tistre / ie_upload.php
Last active August 29, 2015 14:10
Internet Explorer 9 and 10 do not submit the form if a file input click has been triggered
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<?php
if ($_SERVER[ 'REQUEST_METHOD' ] === 'POST')
{
if (isset($_FILES[ 'file' ]) && isset($_FILES[ 'file' ][ 'tmp_name' ]) && is_uploaded_file($_FILES[ 'file' ][ 'tmp_name' ]))
@tistre
tistre / test.js
Last active August 29, 2015 14:11
How I do private and public in JavaScript. No “this”, no “new”! Drawback compared to .prototype: Objects hold copies of functions.
// Factory function
var Greeter = function(config)
{
// Hold public and private variables and functions in two objects:
var _public = { };
var _private = { };
// Storing "constructor" parameters in a private variable
@tistre
tistre / charcheck.php
Created May 29, 2015 11:03
Check files for Unicode U+00A0 No-Break Space
<?php
// Find invisible non-breaking spaces in source code
// which can cause errors in PHP and JavaScript.
//
// see: http://www.strehle.de/tim/weblog/archives/2013/02/26/1563
//
// Usage:
// php charcheck.php path/to/*.php
// or:
@tistre
tistre / planetdam_easyrdf_demo.php
Created July 10, 2015 06:48
Minimal example for parsing planetdam.org RDF/XML using EasyRDF
<?php
/*
Minimal example for parsing http://planetdam.org article list RDF/XML
using http://www.easyrdf.org
1) Install Composer, see http://www.easyrdf.org/docs/getting-started :
curl -s https://getcomposer.org/installer | php
@tistre
tistre / intldateformatter_error_handling.php
Last active December 7, 2015 12:23
Lack of error handling in IntlDateFormatter::localtime()
<?php
// Correct input value:
// $value = 'Wednesday, December 18, 2014 4:05:06 PM PT';
// Wrong input value that I suppose should rather return false:
$value = 'XXX';
$formatter = new IntlDateFormatter
(
@tistre
tistre / js-component-demo-dcc-components.js
Created February 16, 2017 12:59
Simplistic JavaScript component architecture demo
/* A sample "Die" component using the "library" */
/**
* Create a "Die" component instance
*
* Creates an anonymous object you can only interact with using events.
*
* @param object config componentConfig.config object from the component JSON data
* @constructor