Skip to content

Instantly share code, notes, and snippets.

@addorange
addorange / countries.php
Created October 31, 2013 10:00
Array of countries (ISO-coded)
/**
* Countries
*/
$countries = array
(
'ad' => 'Andorra',
'ae' => 'United Arab Emirates',
'af' => 'Afghanistan',
'ag' => 'Antigua and Barbuda',
'ai' => 'Anguilla',
@addorange
addorange / currencies.php
Created October 31, 2013 09:59
Array of currencies (ISO coded)
/**
* Currencies
*/
$currencies = array
(
"ad" => "EUR",
"ae" => "AED",
"af" => "AFN",
"ag" => "USD",
"ai" => "USD",
@addorange
addorange / getUrlVars
Created August 1, 2013 20:10
getUrlVars from url request
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
@addorange
addorange / whoami.php
Created July 5, 2013 22:07
Who runs the server?
<?php echo exec('whoami'); ?>
@addorange
addorange / phpunit.xml.dist
Created July 3, 2013 17:03
phpunit.xml start
<phpunit bootstrap="vendor/autoload.php"
colors="true"
convertErrorToExceptions="true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="App Tests">
@addorange
addorange / Contao 2.11.x - runExternalClass
Created July 3, 2013 10:15
run external class connected to contao (e. g. for AJAX calls)
<?php
require('../system/initialize.php');
class MyClass extends Frontend
{
public function __construct()
{
// Example: Load user object before calling the parent constructor
@addorange
addorange / ctoRequestToJS
Created June 21, 2013 06:06
Contao - Request an JavaScript übergeben
<script type="text/javascript">
window.addEvent('domready', function()
{
var objRequest = JSON.decode(
'<?php echo json_encode($this->Environment->request)?>'
);
alert(objRequest);
});
</script>
@addorange
addorange / drawImageOnCanvasAndSendResultToPHP
Created June 19, 2013 09:32
draw image on canvas and deliver result as base64 to a textarea
<html>
<canvas width='400' height='450' id='canvas'>Ihre Browser ist nicht HTML5-tauglich. Bitte nutzen Sie einen aktuellen Browser.</canvas>
<textarea cols="40" rows="8" name="img" id="result"></textarea>
<script type="text/javascript">
var canvas = document.getElementById('canvas');
var ctxCanvas = canvas.getContext('2d');
@addorange
addorange / createImageFromBase64
Created June 19, 2013 09:26
Copy png from base64 delivery to create an image file
<?php
// Copy png from base64 delivery to create an image file
// requires php5
define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
@addorange
addorange / downloadImage
Created June 19, 2013 09:24
Direct download of an image in PHP
<?php
header('Content-type: image/png');
header('Content-Disposition: attachment; filename="' . $_GET['image'] . '"');
readfile($_GET['image']);
?>