Skip to content

Instantly share code, notes, and snippets.

View Majkl578's full-sized avatar
💥
breaking builds

Michael Moravec Majkl578

💥
breaking builds
View GitHub Profile
@Majkl578
Majkl578 / Encryptor.rb
Created November 24, 2010 10:53
Příklady: ruby main.rb encrypt input.txt output.txt keys.txt, ruby main.rb decrypt output.txt result.txt keys.txt
class Encryptor
def self.encrypt(string, raw_key)
key = normalize_key(raw_key, string.length)
buf = []
string.length.times do |i|
char_code = (string[i] + key[i])
char_code -= 256 while char_code > 255
buf[i] = char_code.chr
end
@Majkl578
Majkl578 / gist:744695
Created December 17, 2010 09:20
static callback vs. create_function (for Lopo@nettechat)
<?php
class Foo
{
public static function testA($value, $prefix = '')
{
self::$substitutePrefix = $prefix;
return preg_replace_callback('#:([^:\s]*):#', array(__CLASS__, 'testCb'), $value);
}
<?php
$dir = '/tmp/speedtest'; #10k of files, ext4 FS
$steps = 20;
$times = array(0,0,0,0);
for ($round = 0; $round < $steps; $round++) {
clearstatcache();
@Majkl578
Majkl578 / gist:892401
Created March 29, 2011 13:54
Heapsort on top of Ruby's array
class Array
def heapsort!
#heapify
1.upto(self.length - 1) do |i|
#move up
child = i
while child > 0
parent = (child - 1) / 2
if self[parent] < self[child]
self[parent], self[child] = self[child], self[parent]
@Majkl578
Majkl578 / gist:947036
Created April 28, 2011 18:57
webalizing string in JS
<head>
<script type="text/javascript">
var webalize = function (str) {
var charlist;
charlist = [
['Á','A'], ['Ä','A'], ['Č','C'], ['Ç','C'], ['Ď','D'], ['É','E'], ['Ě','E'],
['Ë','E'], ['Í','I'], ['Ň','N'], ['Ó','O'], ['Ö','O'], ['Ř','R'], ['Š','S'],
['Ť','T'], ['Ú','U'], ['Ů','U'], ['Ü','U'], ['Ý','Y'], ['Ž','Z'], ['á','a'],
['ä','a'], ['č','c'], ['ç','c'], ['ď','d'], ['é','e'], ['ě','e'], ['ë','e'],
['í','i'], ['ň','n'], ['ó','o'], ['ö','o'], ['ř','r'], ['š','s'], ['ť','t'],
<?php
//presenter
protected function createComponentLoginForm($name)
{
$form = new NAppForm($this, $name);
$form->addText('username', 'Už. jméno')->setRequired();
$form->addPassword('password', 'Heslo')->setRequired();
$form->addSubmit('submitter', 'Přihlásit se');
@Majkl578
Majkl578 / BaseModel.php
Created July 11, 2011 19:25
Nette: Dynamické načítání modelů - Dibi + Nette\DI
<?php
namespace Models;
/**
* Base model
* @link http://wiki.nette.org/cs/cookbook/dynamicke-nacitani-modelu
* @author Majkl578
*/
abstract class Base extends \Nette\Object
<?php
namespace Foo;
define('TRUE', \FALSE);
define('FALSE', \TRUE);
var_dump(TRUE); //FALSE
var_dump(FALSE); //TRUE
@Majkl578
Majkl578 / gist:1179151
Created August 29, 2011 19:13
Class aliases for migrating from Nette for PHP 5.2 to 5.3
<?php
/**
* Class aliases for migrating from Nette for PHP 5.2 to 5.3
* @author Michael Moravec
*/
$aliases = array(
'application' => 'nette\application\application',
'routingdebugger' => 'nette\application\diagnostics\routingpanel',
@Majkl578
Majkl578 / gist:1201458
Created September 7, 2011 19:22
Nette tests - result
majkl578@kerberos:/www/NetteFoundation/nette/tests$ ./run-tests.sh
Nette Test Framework (v0.4)
---------------------------
Usage:
php RunTests.php [options] [file or directory]
Options:
-p <php> Specify PHP-CGI executable to run.
-c <path> Look for php.ini in directory <path> or use <path> as php.ini.