Skip to content

Instantly share code, notes, and snippets.

<?php
declare(strict_types=1);
/**
* @throws LogicException
*/
function matchSomething(TheType $type): string
{
return match ($type->asString()) {
package main
import "fmt"
func main() {
brands := []string{"Mercedes", "Dodge", "Vauxhall"}
fmt.Println("== All Brands")
fmt.Println(brands)
@yarimadam
yarimadam / docker-mysql-backup-restore.md
Created January 31, 2019 08:36
Backup and restore a specific database from a running docker mysql container.

Step 1, dump database via mysqldump.

docker exec CONTAINER_NAME_OR_ID sh -c 'exec mysqldump --databases DATABASE_NAME -uUSER -pPASSWORD' > backup.sql

Step 2, import.

docker exec -i CONTAINER_NAME_OR_ID sh -c 'exec mysql -uUSER -pPASSWORD DATABASE_NAME' < backup.sql

Notice "-i" opiton in the import command. It allows to STDIN contents of the dumped sql file inside the container.

echo `/sbin/ip route|awk '/default/ { print $3 }'` docker.host >> /etc/hosts
@yarimadam
yarimadam / leave_no_trace.sh
Created June 27, 2018 09:25
Clear history and exit bash
cat /dev/null > ~/.bash_history && history -c && exit
@yarimadam
yarimadam / bash_inside_docker_w_autocomplete
Last active July 6, 2018 07:34
bash inside docker container
# put inside ~/.profile or ~/.bashrc
goinside(){
docker exec -it $1 bash -c "stty cols $COLUMNS rows $LINES && bash";
}
_goinside(){
COMPREPLY=( $(docker ps --format "{{.Names}}" -f name=$2) );
}
complete -F _goinside goinside;
export -f goinside;
@yarimadam
yarimadam / background_php_job.php
Created May 22, 2018 07:47
Run php script in background with symfony process component
<?php
require 'vendor/autoload.php';
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
$builder = new ProcessBuilder();
$builder->setPrefix('/usr/local/bin/php');
$cmd = $builder->setArguments(['/Users/tuncay/longRunningTask.php'])
curl http://ipinfo.io/ip
@yarimadam
yarimadam / tree_structure_from_flat_array.php
Created May 2, 2018 11:31
build tree structure from flat array with parent IDs
<?php
$menu = [
1 => ['id' => 1, 'parent' => null, 'name' => 'Root Menu 1'],
2 => ['id' => 2, 'parent' => 1, 'name' => 'Sub Menu 1 > 1'],
3 => ['id' => 3, 'parent' => 1, 'name' => 'Sub Menu 1 > 2'],
4 => ['id' => 4, 'parent' => 2, 'name' => 'Sub Menu 1 > 1 > 1']
];
function buildTree(&$menu)
@yarimadam
yarimadam / fix_setting_locale_failed_error
Last active July 18, 2017 09:15
solve stupid locale error on some linux distro's
* put
LANG=en_US.utf-8
LC_ALL=en_US.utf-8
* to
/etc/environment
* then