Skip to content

Instantly share code, notes, and snippets.

View csarrazi's full-sized avatar

Charles Sarrazin csarrazi

View GitHub Profile
@csarrazi
csarrazi / start_mongo.ps1
Last active May 28, 2019 15:23
Start a local sharded cluster on a local environment.
param(
[Parameter(mandatory = $True)][string]$path,
[switch]$force = $False,
[int]$portPrefix = 27000,
[int]$numShards = 3
)
function LaunchMongoD() {
param(
[string]$processType = "shard",
#^((?P<scheme>[^:/?]+):)?(//(?P<host>[^:/?]*)(:(?P<port>[^/?]*))?)?/(?P<dn>[^?\n]*)(\?(?P<attributes>[^?\n]*)(\?(?P<scope>[^?\n]*)(\?(?P<filter>[^?\n]*)(\?(?P<extensions>[^?\n]*))?)?)?)?$#
ldap://symfony.com:1234/cn=fabien,o=symfony
ldap://symfony.com:1234/cn=fabien,o=symfony?hello
ldap://symfony.com:1234/cn=fabien,o=symfony?hello?base
ldap://symfony.com:1234/cn=fabien,o=symfony?hello,world?one
ldap://symfony.com:1234/cn=fabien,o=symfony?foo,bar,baz?sub
ldap://symfony.com:1234/cn=fabien,o=symfony?foo,bar,baz??(&(objectclass=person)(ou=Maintainers))
ldap://symfony.com:1234/cn=fabien,o=symfony?foo,bar,baz??test?bindname=cn=Fabien%20Potencier,dc=symfony,dc=com
ldap://symfony.com:1234/cn=fabien,o=symfony????bindname=cn=Fabien%20Potencier,dc=symfony,dc=com
@csarrazi
csarrazi / es6.js
Created August 7, 2015 09:28
ES6 classes
class Animal {
constructor(race) {
this.race = race;
}
}
class Cat extends Animal {
constructor(race) {
super(race);
}
@csarrazi
csarrazi / MyController.php
Created July 9, 2015 08:46
Stream a file using a StreamResponse
<?php
use Symfony\Component\DependencyInjection\ContainerAware;
use Csa\Bundle\GuzzleBundle\HttpFoundation\StreamResponse;
class MyController extends ContainerAware
{
public function indexAction()
{
// Call your client
@csarrazi
csarrazi / multigit.sh
Last active August 29, 2015 14:20
Useful commands for working with git repositories from the outside, or managing multiple git repositories in the same folder
#!/bin/bash
rgit () {
if [[ "$#" -lt 2 ]]; then
echo "usage: rgit <repository-path> <command> [<args>]"
return 1
fi
local worktree=$1
shift
@csarrazi
csarrazi / config.yml
Last active May 10, 2016 18:35
Log guzzle requests in a different channel (and a different file)
# http://symfony.com/doc/current/cookbook/logging/channels_handlers.html#switching-a-channel-to-a-different-handler
monolog:
channels: ["guzzle"]
handlers:
main:
type: stream
path: /var/log/symfony.log
channels: ["!guzzle"]
guzzle:
type: stream
@csarrazi
csarrazi / AState.php
Created November 14, 2012 15:38
State pattern in PHP
<?php
class AState extends AbstractState implements StateInterface
{
public function methodA()
{
try {
// Do stuff
// ...
} catch (\Exception $e) {
$this->workflow->setState(new ErrorState($this->workflow, $this));