Skip to content

Instantly share code, notes, and snippets.

View PavelJurasek's full-sized avatar

Pavel Jurásek PavelJurasek

View GitHub Profile
<?php declare(strict_types=1);
namespace App\Ublaboo\DataGrid\DataSource;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Nette\Utils\Strings;
/**
* @method void onDataLoaded(array $result)
*/
@JanTvrdik
JanTvrdik / update-ca-bundle.sh
Last active June 12, 2016 20:59
PHP CA bundle updater
#!/usr/bin/env bash
set -o errexit -o pipefail -o nounset
IFS=$'\n\t'
ROOT_CRT="$(dirname $0)/root/root.crt"
CA_BUNDLE="$(dirname $0)/ca-bundle.pem"
echo -n "Downloading CA bundle... "
wget -q -O "$CA_BUNDLE" https://curl.haxx.se/ca/cacert.pem
echo "done"
@mishak87
mishak87 / netteForms.semantic-ui.js
Created June 11, 2014 22:04
Bridge between semantic ui css framework and nette forms validation
var SemanticUi = typeof SemanticUi == 'undefined' ? {} : SemanticUi;
SemanticUi.netteForms = {};
SemanticUi.netteForms.currentError = null;
SemanticUi.netteForms.firstError = null;
/**
* Replaces default Nette behaviour to support SemanticUI theme
*/
SemanticUi.netteForms.addError = function (elem, message) {
@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

@codeguy
codeguy / geocode-address.js
Created September 24, 2013 18:37
Geocode address with Google Maps API
/**
* Geocode address
*
* REQUIREMENTS
* - Google Maps API
* - HTML5 Geolocation API
*/
var geocode = function (address, onSuccess, onError) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: address }, function (results, status) {
@codeguy
codeguy / get-current-location.js
Created September 24, 2013 18:33
Get user's current gelocation with HTML Geolocation API
if ('geolocation' in navigator) {
console.log('Supports HTML geolocation API');
(function () {
var onSuccess = function (location) {
console.log('User location', location);
var userLat = location.coords.latitude,
userLon = location .coords.longitude;
},
@pavelkucera
pavelkucera / Extension.php
Last active December 20, 2015 22:59
How to add a factory taking parameter into Nette DIC. Both ways, using config.neon and compiler extension, have the same result.
<?php
class Extension extends \Nette\DI\CompilerExtension
{
public function loadConfiguration()
{
$container = $this->getContainerBuilder();
$container->addDefinition($this->prefix('formMapperFactory'))
->setImplement('Namespace\IFactory')
@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) {
@juzna
juzna / 01-server-config-in-git.md
Last active November 9, 2021 07:27
Server Configuration in git

Server Configuration in git

With git you can have anything versioned. You're used to version your code, which is a bunch of files. Your server configuration (on Linux) is also just a bunch of files, so it can be versioned as well.

The idea is simple: create a git repository in /etc/ and commit everytime you change any configuration of your server. Written in code:

cd /etc
git init
git add .
@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);