Skip to content

Instantly share code, notes, and snippets.

View chalasr's full-sized avatar

Robin Chalas chalasr

View GitHub Profile
@chalasr
chalasr / bootstrap.sh
Created April 29, 2020 13:09 — forked from keo/bootstrap.sh
Setup encrypted partition for Docker containers
#!/bin/sh
# Setup encrypted disk image
# For Ubuntu 14.04 LTS
CRYPTFS_ROOT=/cryptfs
apt-get update
apt-get -y upgrade
apt-get -y install cryptsetup
@chalasr
chalasr / script.lua
Created July 7, 2019 19:04 — forked from chanks/script.lua
Lua script to delete/trim all processed messages from a Redis stream
-- The goal of this script is to trim messages that have been processed by
-- all extant groups from the a given Redis stream. It returns the number
-- of messages that were deleted from the stream, if any. I make no
-- guarantees about its performance, particularly if the stream is large
-- and not fully processed (so a simple XTRIM isn't possible).
-- First off, bail out early if the stream doesn't exist.
if redis.call("EXISTS", KEYS[1]) == 0 then
return false
end
@chalasr
chalasr / coroutine.php
Created October 27, 2018 21:00 — forked from nikic/coroutine.php
A coroutine example: Streaming XML parsing using xml_parser
<?php
error_reporting(E_ALL);
/* Data can be send to coroutines using `$coroutine->send($data)`. The sent data will then
* be the result of the `yield` expression. Thus it can be received using a code like
* `$data = yield;`.
*/
/* What we're building in this script is a coroutine-based streaming XML parser. The PHP
@chalasr
chalasr / Symfony2 GraphvizDumper demo
Created June 7, 2017 14:50 — forked from fgm/Symfony2 GraphvizDumper demo
Demonstrate how to use the GraphViz Dumper in a Symfony 2.4 project.
<?php
/**
* @file
* gvdump.php
*
* @author: Frédéric G. MARAND <[email protected]>
*
* @copyright (c) 2014 Ouest Systèmes Informatiques (OSInet).
*
* @license MIT
@chalasr
chalasr / pthreads.md
Created May 10, 2017 21:56 — forked from krakjoe/pthreads.md
pthreads.md

Multi-Threading in PHP with pthreads

A Brief Introduction to Multi-Threading in PHP

  • Foreword
  • Execution
  • Sharing
  • Synchronization
  • Pitfalls
@chalasr
chalasr / example.md
Created July 7, 2016 11:59 — forked from ericclemmons/example.md
HTML5 <details> in GitHub

Using <details> in GitHub

Suppose you're opening an issue and there's a lot noisey logs that may be useful.

Rather than wrecking readability, wrap it in a <details> tag!

<details>
 <summary>Summary Goes Here</summary>
@chalasr
chalasr / is_serialized.php
Created March 7, 2016 17:36 — forked from cs278/is_serialized.php
PHP is_serialized() function.
<?php
/**
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
/**
@chalasr
chalasr / proceduralphp.md
Created February 10, 2016 00:30 — forked from InFog/proceduralphp.md
PHP Procedural Framework Manifesto

Procedural PHP Manifesto

We are web site developers (a.k.a. webmasters) and we just want to get stuff done. We don't need Object Orientation and we don't need Design Patters and other boring and not easy to learn and understand stuff to get in our way to get our sites up and running.

And that's why our values are:

  1. Procedural Code over Object Orientation
  • Classes with only static functions are ok, since it's just a way to keep functions in one place. And is still procedural
  1. Explicitly load what you need over autoloaders
  • Autoloaders are complex and can fail. Just include() what you need
@chalasr
chalasr / DoctrineDbalStatementInterface.php
Created February 1, 2016 12:28 — forked from gnutix/DoctrineDbalStatementInterface.php
Mock Builder for Doctrine EntityManager / Connection mock objects.
<?php
namespace Mocks;
use Doctrine\DBAL\Driver\Statement;
/**
* Doctrine DBAL Statement implementing \Iterator.
*
* This class has been created because of a bug in PHPUnit Mock Objects.
@chalasr
chalasr / fosuser_password_generator.php
Last active January 20, 2016 10:16 — forked from Kydoh/new_gist_file
Generate random password (require FOSUserBundle)
<?php
$tokenGenerator = $this->getContainer()->get('fos_user.util.token_generator');
$password = substr($tokenGenerator->generateToken(), 0, 8); // 8 chars