Skip to content

Instantly share code, notes, and snippets.

View jiripudil's full-sized avatar

Jiří Pudil jiripudil

View GitHub Profile
@jiripudil
jiripudil / responsiveImages.html
Created September 5, 2012 18:52
Mobile-first responsive images using jQuery
<img src="/mobile/version.jpg" data-tablet-src="/tablet/version.jpg" data-full-src="/full/version.jpg" alt="Picture" class="responsive">
@jiripudil
jiripudil / gist:3883912
Created October 13, 2012 09:10
Select months by presence of entries
# select only those months for which there is at least one entry in the database table
# datetime column is DATE or DATETIME
SELECT DISTINCT(MONTH(datetime)) AS month, YEAR(datetime) AS year FROM post ORDER BY year, month
# returns table with distinct year-month pairs
@jiripudil
jiripudil / FileDumpMailer.php
Created April 4, 2013 19:06
Mailer for Nette that saves messages as EML files, for debug purposes
<?php
/**
* @copyright Copyright (c) 2013, Jiří Pudil
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace jiripudil\Mail;
@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}
@jiripudil
jiripudil / gist:5627154
Last active December 17, 2015 14:49
Snippet that allows you to inspect elements in Google Chrome Dev Tools with a single click
document.addEventListener('click', function (e) {
// the combination can be changed easily
// in this case it is Ctrl + Shift + MMB
if (e.button == 1 && e.ctrlKey && e.shiftKey) {
// fire up Inspector focused on the clicked element
inspect(e.target);
// prevent default action (e.g. do not click through links)
e.preventDefault();
// prevent the event from bubbling further through the DOM
e.stopImmediatePropagation();
@jiripudil
jiripudil / spinner.html
Created August 17, 2013 17:32
Pure JavaScript spinner
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pure JS spinner</title>
<style>
#spinner { font-size: 6em; }
</style>
@jiripudil
jiripudil / fuck
Created October 16, 2013 11:10
A script that comes in handy when you are dealing with Unix problems and you get desperate.
#!/bin/sh
if [ -z $1 ]; then
echo "Don't swear!" # or similar motivating phrase
exit 2
fi
case $1 in
you)
sudo reboot
@jiripudil
jiripudil / partial.php
Created January 9, 2015 10:53
Helper function for partial application in PHP
<?php
function partial(callable $closure, ...$partialArgs) {
return function (...$args) use ($closure, $partialArgs) {
return call_user_func($closure, ...$partialArgs, ...$args);
};
}
// demo

Keybase proof

I hereby claim:

  • I am jiripudil on github.
  • I am jiripudil (https://keybase.io/jiripudil) on keybase.
  • I have a public key whose fingerprint is 78A0 8508 7D11 76DD 9F25 24B8 D334 4DC7 AAE0 703D

To claim this, I am signing this object:

@jiripudil
jiripudil / @layout.latte
Created October 25, 2016 14:31
Nette ♥ webpack-dev-server
<!DOCTYPE html>
<html lang="cs">
<head>
<title>{block title}Foo{/block}</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="{$bundlePath}/styles.css" rel="stylesheet">
</head>
<body>
{include #content}