Skip to content

Instantly share code, notes, and snippets.

View sheeep's full-sized avatar
🐑

Jim Schmid sheeep

🐑
View GitHub Profile
@dextervip
dextervip / PostgreSqlPlatform.php
Last active April 25, 2024 10:54
Symfony Doctrine support for timescaledb
<?php
namespace App\Domain\Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform as PostgreSqlPlatformBase;
class PostgreSqlPlatform extends PostgreSqlPlatformBase
{
@jasperkuperus
jasperkuperus / DiscriminatorListener.php
Last active July 7, 2023 17:35
This gist shows you how to define your discriminator maps at child level in doctrine 2. Why? Because your parent class shouldn't be aware of all it's subclasses. Please read my article for more explanation: https://medium.com/@jasperkuperus/defining-discriminator-maps-at-child-level-in-doctrine-2-1cd2ded95ffb
<?php
namespace My\Namespace;
/**
* This Listener listens to the loadClassMetadata event. Upon this event
* it hooks into Doctrine to update discriminator maps. Adding entries
* to the discriminator map at parent level is just not nice. We turn this
* around with this mechanism. In the subclass you will be able to give an
* entry for the discriminator map. In this listener we will retrieve the
* load metadata event to update the parent with a good discriminator map,
@lyrixx
lyrixx / segfault-finder.php
Last active August 15, 2023 21:17
How to find a segfault in PHP
<?php
register_tick_function(function() {
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
$last = reset($bt);
$info = sprintf("%s +%d\n", $last['file'], $last['line']);
file_put_contents('/tmp/segfault.txt', $info, FILE_APPEND);
// or
// file_put_contents('php://output', $info, FILE_APPEND);
});
@jbenet
jbenet / simple-git-branching-model.md
Last active July 21, 2025 21:02
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

Awesome PHP Libraries

A list of amazingly awesome PHP libraries that you should consider using (and some other shiny extras).

Snow in canvas land

Other peoples' code is awful, and your own code from months previous counts as someone else's. With this and the festive spirit in mind, I dug up a canvas snow demo I made two years ago to see how bad my code really was.

How does it work?

Snowflake objects are created with a radius, opacity, y-velocity, and x-range (they drift from side to side). As they fall, they're drawn to a canvas, this canvas is cleared on every frame. When snowflakes land, they're drawn to another canvas, and the Snowflake is removed from the "active snowflakes" list. The second canvas is never cleared, snowflakes shapes are added as they land, meaning I don't have to redraw all the landed snowflakes per frame.

Two years of browser development later, what's wrong with it?

@mheiniger
mheiniger / ubuntu-php-development-environment.md
Created November 19, 2012 22:51 — forked from DaRaFF/ubuntu-php-development-environment.md
Ubuntu php development environment

#Introduction If you're a php developer on ubuntu, there comes the time where you have to install/reinstall your system. I did it already a few times and i decided to write down the steps for a typical web developer stack with php. This is for a developer machine and not for live environment!

I hope it's a help also for you!

#Installation stack

@Ocramius
Ocramius / LazyLoadableObject.php
Created November 8, 2012 10:30
DCOM-96 generated proxy example
<?php
/**
* @author Marco Pivetta <ocramius@gmail.com>
*/
class LazyLoadableObject
{
public $publicIdentifierField;
protected $protectedIdentifierField;
@ivan-ivanic-cm
ivan-ivanic-cm / pull that embed out
Created May 31, 2012 17:38
Deleting embedded document from document, MongoDB shell with $pull
> use test_database
> var pu = db.Profileusers
> pu.find({"blocks.title":""}).toArray() // find in Profileusers collection all profile users that have a block which title is empty
[
{
"_id" : ObjectId("4fc73221c0cd99aba79c7b74"),
"blocks" : [
{
"_id" : ObjectId("4fc78936376ab08618000000"),
"title" : "", // <-- here is the incriminating element, it's gonna fly muaaahaaaaaaa-ha-ha-ha (evil_grin)