Skip to content

Instantly share code, notes, and snippets.

View vojtech-dobes's full-sized avatar

Vojtěch Dobeš vojtech-dobes

View GitHub Profile
<?php
function array_map_recursive($f, $xs) {
$out = [];
foreach ($xs as $k => $x) {
$out[$k] = (is_array($x)) ? array_map_recursive($f, $x) : $f($x);
}
return $out;
}
@lm
lm / index.php
Last active July 24, 2020 15:30
<?php
class AdminerColors
{
function head()
{
static $colors = array(
'127.0.0.1' => '#ED1C24',
'localhost' => '#009245',
@juzna
juzna / flow.md
Last active March 14, 2016 17:28
Cooperative Multitasking Components in Nette Framework example

Cooperative Multitasking, Components, Nette & Flow

On GitHub I provide example or Cooperative Multitasking components on a single site served by Nette Framework. These components need to process several network requests to render themselves, which is normally slow.

This example takes advantage of yield operator (available since PHP 5.5) to switch between tasks, Flow as scheduler and Rect as parallel http client.

This post introduces the Flow framework and cooperative multitasking in general.

The Example Application

@garann
garann / gist:6541294
Created September 12, 2013 17:47
how to blog about code and give zero fucks

I’m frustrated right now. I’ve been looking for someone to write about a technology that tons of people have no doubt used and am coming up short. Really, this is my own fault, because I was hoping I’d find someone who wasn’t a white male to address the topic. There’s nothing wrong with a white male addressing the topic, but I’ve been recommending a lot of white males to write about technologies and I was hoping to put my money where my mouth is in terms of my hopes for the diversity of the field in which I work.

I checked a bunch of related repos on GitHub and found that the maintainers were white guys and the committers were white guys and the people filing issues were white guys. So I checked the Following lists of related Twitter accounts and found.. more white guys. The few women I found either didn’t blog or had Tumblrs full of inspirational quotes and cupcake photos and shit. (Which is fine. But not what I happened to be looking for an expert on.)

And so this is how I became frustrated, because I d

@dg
dg / websocket.html
Created August 11, 2013 15:54
WebSocket communication between PHP and single client
<!doctype html>
<script>
if ("WebSocket" in window) {
var ws = new WebSocket("ws://127.0.0.1:31339");
ws.onopen = function() {
console.log('connected');
};
ws.onerror = function(e) {
@Majkl578
Majkl578 / watcher.php
Created July 6, 2013 19:54
Simple realtime inotify-based script watching for file updates, updates all files on update. Requires inotify extension, can be found at http://pecl.php.net/package/inotify. Usage: $ php scripts/watcher.php doc-2.0 cs ../web-content /tmp/webcontent Based on https://github.com/nette/web-content/tree/convertor
<?php
/**
* Simple realtime inotify-based script watching for file updates, updates all files on update.
* Requires inotify extension, can be found at http://pecl.php.net/package/inotify.
* Usage: $ php scripts/watcher.php doc-2.0 cs ../web-content /tmp/webcontent
* @author Michael Moravec
*/
require __DIR__ . '/../vendor/autoload.php';
@dg
dg / output detector.php
Created June 20, 2013 18:59
How can I find out where my output started?
<?php
ob_start(function($s, $flag) {
if ($flag & PHP_OUTPUT_HANDLER_START) {
$e = new \Exception;
$s = nl2br("Output started here:\n{$e->getTraceAsString()}\n\n") . $s;
}
return $s;
}, 2);
@dg
dg / gist:5616877
Created May 21, 2013 01:09
Workaround for missing ::class in PHP < 5.5
<?php
use Nette\Http;
echo Http\Request::class; // prints 'Nette\Http\Request' since PHP 5.5
echo Http\Request\type::of; // prints 'Nette\Http\Request' alwyas ;)
using System;
class Program
{
static void Main()
{
var result1 = Authenticate("me", "password");
PrintAuthResult(result1);
var result2 = Authenticate("ja", "heslo");
@jiripudil
jiripudil / text.md
Last active December 16, 2015 11:19
Write secure templates with Latte

Write secure templates with Latte

Writing templates can be a pain. Securing it against cross-site scripting attacks can be even worse. Sick of writing htmlspecialchars($output, ENT_QUOTES) again and again? And using htmlentities() instead when escaping input for a JavaScript snippet? Why bother when there is a templating engine that can take care of all this dirty business?

Latte is a templating engine that comes shipped as a part of Nette framework, an open-source PHP framework of Czech origin. It is dual-licensed under New BSD and GNU GPL licenses. Latte automatically secures your templates against XSS exploits using context-aware escaping. And it makes writing templates a pleasure.

So, how do you output a variable in a secure way? Simply:

{$variable}