Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
# download
wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.4.zip
# unzip and start
unzip elasticsearch-0.20.4.zip
cd elasticsearch-0.20.4
# remove data in case you have defined some analyzers in the past (e.g. stop/start)
rm -rf data/
@juzna
juzna / example.php
Created December 1, 2012 16:42
SessionId and randomness in PHP
<?php
/**
* Starts a PHP session and dump a random number
*/
session_start();
// do some stuff...
$password = mt_rand();
$otherRandomToken = rand();
@juzna
juzna / 2012-11-17-intellij-plugins-lexer-tests.md
Created November 17, 2012 19:51
IntelliJ plugins - Lexer + Tests

IntelliJ plugins - Lexer + Tests

We're writing support for Neon language into PhpStorm and we want to have it heavily tested with automated unit tests. First step when processing any programming language is a lexical analyzer or shortly lexer, which takes source code and splits into individual words of the programming language, which are called tokens (actually, also symbols, punctuation and whitespace count as tokens).

JFlex

Because parsing strings manually is tedious and boring, clever people made tools to help us a little bit. Flex is de facto standard language for writing lexers, but we'll use its port to Java called JFlex. In flex files you describe patterns for several types of tokens and associate a piece of code with each. Have a look at flex file for very simple [properties](https://github.com/JetBrains/intellij-community/blob/master/plugins/properties/src/com/intellij/lang/properties/pa

@juzna
juzna / retina.js
Created October 12, 2012 22:47
Retina images quality simulator
/**
* Simulates how normal low-res images look on retina display
*
* It resamples all images (within <img> tags) to a lower resolution.
* We should use half the resolution of original image to be precise (because retina has 2x the density of pixels),
* but that doesn't show * perceived* effect. It's enough to scale by 1.75.
*
* Also, it would be good to resample also images used in CSS background, but I dunno how to do it :/
*
* Requires jQuery
@juzna
juzna / utils.php
Created October 2, 2012 17:06
unserialize() with encoding conversion
<?php
/**
* Hacked unserialize: works when encoding changed after serialization
* Problem: serialize cp1250, convert to utf8, unserialize. Length in bytes is bigger now!
*
* Also, it throws when something else is wrong
*
* @param string $s
@juzna
juzna / tst.php
Created September 3, 2012 21:56
PHP WTF? Error handler is not called, when display_errors=On
<?php
/**
* WTF? Error handler is not called, when display_errors=On
*/
function _errorHandler($severity, $message, $file, $line, $context) {
$GLOBALS['err'] = func_get_args();
// echo "Error ($severity) $message in $file:$line\n";
}
@juzna
juzna / php-enhancer.md
Created August 23, 2012 20:54
PHP Enhancer - Enhance PHP syntax now

PHP Enhancer

Enhance PHP syntax now.

Motivation

Is there something you don't like about PHP's syntax? Would you like to upgrade it a little bit, if it wouldn't be that difficult? PHP itself is written in C, so if you wanna change something, you'd have to learn C, right?

"No, thanks. I don't wanna learn C and spend long nights debugging memory leaks etc. I wanna just try something out and then probably discard it anyway. Just play around, experiment..."

@juzna
juzna / intro.md
Created August 20, 2012 19:19
Nette\Object performance tests

Nette\Object performance tests

I guess you already saw a short note Latency Numbers Every Programmer Should Know. I wanted to check how well Nette performs with its magic properties on Nette\Object.

You can see the testing code below together with raw output on my machine.

It show how much time in seconds it took to execute one million iterations of a particular action, thus it is also time in microseconds of one such call. You should compare it to null test, which execute empty iterations.

Results

@juzna
juzna / backup-with-git.md
Created August 5, 2012 16:23
Simple backups with Git

Simple backups with Git

Git calls itself "stupid content tracker", which means that the core just stores any data you put in and allows you to get it back. On top of that, there's all the fancy stuff like branching, diffs, remote repos etc, but that's not important for us today. We just want to track content, and the more stupidier (i.e. simple) way, the better - it'll be simpler to do any crazy stuff we imagine later on.

Motivation

I wanted to do backups of couple of terabytes of data, consisting of quite small files (< 10MB) which usually don't change. I wanted to have incremental backups (not to transfer all data) and I wanted to see history and be able to get into any version.

So why not to use git for it?

@juzna
juzna / index.html
Created August 3, 2012 15:34
Bookmarklets
<h1>Bookmarklets</h1>
<p>Usefull bookmarklets. Drag & drop them to your bookmark bar and then use whenever needed</p>
<ul>
<li><a href="javascript:var s = document.createElement('script'); s.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'; document.body.appendChild(s)">Add jQuery</a> - adds jQuery to current page
<li><a href="javascript:$.post("http://ladenka.juzna.cz/record/add?message="+$("#netteBluescreenError p")[0].firstChild.nodeValue.trim(),{content:document.getElementById("netteBluescreen").innerHTML},function(a){if(a&&a.link){window.open(a.link)}else{alert("Uploaded failed")}})">Share BlueScreen</a> - share Nette BlueScreen to the cloud (https://github.com/nette/nette/pull/717)