Skip to content

Instantly share code, notes, and snippets.

View dkesberg's full-sized avatar

Daniel Kesberg dkesberg

View GitHub Profile
<?php
/**
* Formats a JSON string for pretty printing
*
* @param string $json The JSON to make pretty
* @param bool $html Insert nonbreaking spaces and <br />s for tabs and linebreaks
* @return string The prettified output
* @author Jay Roberts
*/
@dkesberg
dkesberg / UserController.php
Last active July 1, 2019 04:42
Laravel UserController with basic login function which converts old passwords on the first login. Based on http://stackoverflow.com/a/19880068
<?php
use Illuminate\Support\MessageBag;
class UserController extends BaseController {
public function loginView()
{
$errors = new MessageBag();
<?php
/* app/validators.php */
Validator::extend('alpha_spaces', function($attribute, $value)
{
return preg_match('/^[\pL\s]+$/u', $value);
});
/*
@dkesberg
dkesberg / style.css
Last active August 29, 2015 13:56
Foundation CSS: Remove top bar background
.top-bar {
background: none;
}
.top-bar-section ul {
background: none;
}
.top-bar-section ul li>a,
.top-bar-section ul li:hover>a,
.top-bar-section li:not(.has-form) a:not(.button)
.top-bar-section li:not(.has-form) a:not(.button):hover {
<?php
namespace Acme\MyBundle\Service;
use Symfony\Component\HttpFoundation\File\File;
use Imagine\Image\ImagineInterface;
use Imagine\Image\BoxInterface;
use Imagine\Image\Point;
use Imagine\Image\Box;
@dkesberg
dkesberg / ItemController.php
Created February 24, 2014 12:00
Laravel workaround for Symphony Download Response Error: "the filename fallback must only contain ASCII characters". Creates a tempfile for download. Also registers a shutdown function to clean tmp dir.
<?php
/**
* @author Daniel Kesberg <[email protected]>
* @copyright (c) 2014, Daniel Kesberg
*/
class ItemController extends BaseController
{
public function download(Item $item)
{
@dkesberg
dkesberg / bootstrap-fileinput.css
Created April 17, 2014 13:22
file input styling for bootstrap 3
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
@dkesberg
dkesberg / slim.hooks.php
Last active August 29, 2015 14:04
slim hook to detect browser language and set laravel translator
<?php
use Illuminate\Translation\Translator;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Translation\FileLoader;
$app->languages = ['en', 'de'];
$app->hook('slim.before', function() use ($app) {
$env = $app->environment();
.grid { margin:1em auto; border-collapse:collapse }
.grid td {
cursor:pointer;
width:30px; height:30px;
border:1px solid #ccc;
text-align:center;
font-family:sans-serif; font-size:13px
}
.grid td.clicked {
background-color:yellow;
@dkesberg
dkesberg / transparent.php
Last active May 31, 2017 19:47
Transparent 1x1 image (png, gif)
/**
* source: http://stackoverflow.com/questions/3203354/php-script-to-render-a-single-transparent-pixel-png-or-gif
*/
// transparent 1x1 png
header('Content-Type: image/png');
echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=');
// transparent 1x1 gif
header('Content-Type: image/gif');