Skip to content

Instantly share code, notes, and snippets.

View vojtech-dobes's full-sized avatar

Vojtěch Dobeš vojtech-dobes

View GitHub Profile
using System;
class Program
{
static void Main()
{
var result1 = Authenticate("me", "password");
PrintAuthResult(result1);
var result2 = Authenticate("ja", "heslo");
@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 ;)
@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);
@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 / 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) {
@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

@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

@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',
<?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;
}
@mislav
mislav / backfill-releases.sh
Created February 5, 2014 17:37
Script to migrate releases from CHANGELOG.md to GitHub Releases
#!/bin/bash
# Usage: OAUTH_TOKEN="..." backfill-releases CHANGELOG.md [<project-title>]
set -e
log="${1?}"
project_name="${2}"
repo="$(git config remote.origin.url | grep -oE 'github\.com[/:][^/]+/[^/]+' | sed 's/\.git$//' | cut -d/ -f2-3)"
[ -n "${project_name}" ] || project_name="${repo#*/}"