Skip to content

Instantly share code, notes, and snippets.

View janbarasek's full-sized avatar
🏠
Working from Prague

Jan Barášek janbarasek

🏠
Working from Prague
View GitHub Profile
@dg
dg / template.latte
Created August 26, 2011 04:34
Výhody šablonovacího systému Latte

Zadáním je jednoduchý a zcela běžný úkol:

  • vypisuju nebufferované data z databáze (tj. neznám dopředu počet položek) jako elementy
  • každý lichý bude mít class="lichy"
  • poslední bude mít třídu class="posledni" (tedy class="posledni lichy", bude-li poslední zároveň lichý)
  • protože jsme puntičkáři, nechceme v kódu žádné prázdné
  • apod.
  • a samozřejmě veškerý výstup musí být escapovaný (tj. ošetřený)
@ircmaxell
ircmaxell / Expressions.php
Created September 21, 2011 16:51
A math parser and evaluator implementation
<?php
class Parenthesis extends TerminalExpression {
protected $precidence = 6;
public function operate(Stack $stack) {
}
public function getPrecidence() {
return $this->precidence;
@tawfekov
tawfekov / generator.php
Last active October 4, 2024 11:37
Doctrine2 Generate Entities form Existing Database
<?php
include '../vendor/autoload.php';
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();
// config
$config = new \Doctrine\ORM\Configuration();
@bubba-h57
bubba-h57 / closeConnection.php
Created January 14, 2015 21:39
Easy way to close connections to the browser and continue processing on the server.
<?php
/**
* Close the connection to the browser but continue processing the operation
* @param $body
*/
public function closeConnection($body, $responseCode){
// Cause we are clever and don't want the rest of the script to be bound by a timeout.
// Set to zero so no time limit is imposed from here on out.
set_time_limit(0);
@mindplay-dk
mindplay-dk / session-life-cycle.md
Last active August 26, 2024 23:46
Complete overview of the PHP SessionHandler life-cycle

This page provides a full overview of PHP's SessionHandler life-cycle - this was generated by a set of test-scripts, in order to provide an exact overview of when and what you can expect will be called in your custom SessionHandler implementation.

Each example is a separate script being run by a client with cookies enabled.

To the left, you can see the function being called in your script, and to the right, you can see the resulting calls being made to a custom session-handler registed using session_set_save_handler().

@daraul
daraul / decodeHtmlspecialChars.js
Last active February 11, 2024 01:18
Decode PHP's htmlspecialchars encoding with Javascript
return function(text) {
var map = {
'&amp;': '&',
'&#038;': "&",
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
'&#039;': "'",
'&#8217;': "’",
'&#8216;': "‘",
@rodrigoborgesdeoliveira
rodrigoborgesdeoliveira / ActiveYouTubeURLFormats.txt
Last active November 1, 2024 15:01 — forked from ScottCooper92/gist:ea11b690ba4b1278e049
Example of the YouTube videos URL formats
http://www.youtube.com/watch?v=-wtIMTCHWuI
http://youtube.com/watch?v=-wtIMTCHWuI
http://m.youtube.com/watch?v=-wtIMTCHWuI
https://www.youtube.com/watch?v=lalOy8Mbfdc
https://youtube.com/watch?v=lalOy8Mbfdc
https://m.youtube.com/watch?v=lalOy8Mbfdc
http://www.youtube.com/watch?v=yZv2daTWRZU&feature=em-uploademail
http://youtube.com/watch?v=yZv2daTWRZU&feature=em-uploademail
http://m.youtube.com/watch?v=yZv2daTWRZU&feature=em-uploademail
@dg
dg / patch-CVE-2020-15227.php
Last active December 22, 2020 16:28
CVE-2020-15227 nette/application RCE in-place patch
<?php
# In-place apply the CVE-2020-15227 nette/application patch
# This is a universal patcher for all affected versions.
# Run with `php patch-CVE-2020-15227.php`
# Inspiration: @spazef0rze