Skip to content

Instantly share code, notes, and snippets.

View salahm's full-sized avatar

Salah MEHARGA salahm

View GitHub Profile
@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);