Skip to content

Instantly share code, notes, and snippets.

View salahm's full-sized avatar

Salah MEHARGA salahm

View GitHub Profile
@salahm
salahm / messenger-behat.php
Created March 20, 2019 17:16
Get dispatched messages with messenger and behat
<?php
$driver = $this->session->getDriver();
/** @var Client $client */
$client = $driver->getClient();
$nbDispatchedMessages = count($client->getProfile()->getCollector('messenger')->getMessages());
if ($count !== $nbDispatchedMessages) {
throw new ExpectationException(
sprintf('Dispatched messages should be equal to %s, actual : %s', $count, $nbDispatchedMessages),
$driver
);
@salahm
salahm / keybase.md
Created July 30, 2018 09:52
keybase.md

Keybase proof

I hereby claim:

  • I am salahm on github.
  • I am salahm (https://keybase.io/salahm) on keybase.
  • I have a public key ASDGxm2dMmoxnD9S3c3SiU4MBb98CZBCVsNpEERlrgHN2Qo

To claim this, I am signing this object:

@salahm
salahm / gist-history.sh
Created July 17, 2017 10:09 — forked from dunglas/gist-history.sh
Extract interesting commits from a Git repository
# All commits
git log --all --after="2016-01-01 00:00" --before="2017-01-01 00:00" --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short --no-merges --first-parent master --author-date-order --reverse > ~/cir/api-platform-standard-edition
# Commits from a specific author
git log --all --after="2016-01-01 00:00" --before="2017-01-01 00:00" --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short --no-merges --first-parent master --author-date-order --reverse --author="dunglas@gmail.com"

There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.

All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.

  1. Loop variables are scoped outside the loop.

What do these lines do? Make predictions and then scroll down.

func print(pi *int) { fmt.Println(*pi) }
@salahm
salahm / fluent-setters.md
Created August 25, 2016 12:32 — forked from Nicofuma/fluent-setters.md
PHPStrom templates (PHP 5 & 7, type hint arrays, string[] support, ...)
#set($typeHintText = "$TYPE_HINT")
#set($nonTypeHintableTypes = ["", "string", "int", "mixed", "number", "void", "object", "real", "double", "float", "resource", "null", "bool", "boolean"])
#foreach($nonTypeHintableType in $nonTypeHintableTypes)
    #if ($nonTypeHintableType == $TYPE_HINT)
        #set($typeHintText = "")
    #end
#end

#if ($typeHintText.matches('^((\\)?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)+$'))
@salahm
salahm / segfault-finder.php
Created July 19, 2016 13:29 — forked from lyrixx/segfault-finder.php
How to find a segfault in PHP
<?php
register_tick_function(function() {
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
$last = reset($bt);
echo sprintf("%s +%d\n", $last['file'], $last['line']);
});
declare(ticks=1);
@salahm
salahm / pxtoem
Created December 5, 2012 15:19
Sass - Px to em
@function pxtoem($cible, $contexte: $base-font-size) {
@if $cible == 0 { @return 0 }
@return $cible / $contexte + 0em;
}