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
@beberlei
beberlei / DoctrineTestCase.php
Created September 14, 2012 21:14
Doctrine Test Setup
<?php
// tests/MyProject/Tests/DoctrineTestCase.php
namespace MyProject\Tests;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\EntityManager;
class DoctrineTestCase extends \PHPUnit_Framework_TestCase
{
protected $em;
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 11, 2025 00:12
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@vojtech-dobes
vojtech-dobes / MultiAuthenticator.php
Created August 31, 2012 12:40
Multiple ways of authentication in Nette
<?php
namespace VojtechDobes\NetteSecurity;
use Nette\InvalidArgumentException;
use Nette\Security\IAuthenticator;
use Nette\Security\IIdentity;
/**
@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

@beberlei
beberlei / proxies.php
Created August 6, 2012 18:25
Proxies with public properties
<?php
class Foo
{
public $foo;
}
class FooProxy extends Foo
{
public function __construct()
@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?

@beberlei
beberlei / User.php
Created July 9, 2012 09:29
Customize Trait Doctrine Mappings with AttributeOverride
<?php
namespace MyBundle\Entity;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="id", column=@ORM\Column(name="table_id"))
@vojtech-dobes
vojtech-dobes / add_pull_request_to_issue_github.sh
Created June 22, 2012 12:29 — forked from JanTvrdik/add_pull_request_to_issue_github.sh
Add pull request to existing issue on github
#!/bin/bash
current_branch="$(git symbolic-ref HEAD 2>/dev/null)" || current_branch="(unknown)"
current_branch=${current_branch##refs/heads/}
if [[ $current_branch = "(unknown)" ]]
then
echo "Unable to determine current branch!"
exit 1
fi
@jboner
jboner / latency.txt
Last active May 10, 2025 11:02
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@ondrejmirtes
ondrejmirtes / in_array.php
Created May 24, 2012 10:47
PHP WTFs - in_array()
<?php
$keys = array(
'scheme',
'user',
'pass',
'host',
'port',
'path',
'query',