Skip to content

Instantly share code, notes, and snippets.

@addorange
addorange / MySQL - CopyDataBetweenTables
Created May 31, 2013 08:01
MySQL - Copy data from one table to another, even if they have different structures
INSERT INTO `s_campaigns_mailaddresses` (`customer`,`email`)
SELECT '1', `email`
FROM `s_user`
@addorange
addorange / sameHeightBootstrap
Created June 19, 2013 09:21
Same height for spans inside Twitter Bootstrap row (jQuery)
boxes = $('.well');
maxHeight = Math.max.apply(
Math, boxes.map(function() {
return $(this).height();
}).get());
boxes.height(maxHeight);
@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']);
?>
@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 / 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 / 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 / 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 / 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 / whoami.php
Created July 5, 2013 22:07
Who runs the server?
<?php echo exec('whoami'); ?>
@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];