This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('HOST_SUFFIX', '.local'); | |
/** | |
* @return string[] | |
*/ | |
function determineIpAddresses() | |
{ | |
$lines = array_slice(explode(PHP_EOL, shell_exec('docker-compose ps')), 2, -1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Assumption 1: $CONTAINER and $HOST are properly set | |
# Assumption 2: The host is already set in /etc/hosts. | |
# Assumption 3: In /etc/hosts, the IP address and host are separated by a tab | |
IP=`docker exec -t $CONTAINER ip addr | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | grep 172` | |
sudo sed -i "/$HOST/s/[^\t]*/$IP/" /etc/hosts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = [ | |
'name' => ['a', 'b', 'c'], | |
'email' => ['a@bc.de', 'x@yz.de', 'barde@bar.de'], | |
]; | |
$output = []; | |
for($i = 0; $i < count($data['name']); $i++) { | |
$output[] = array_combine(array_keys($data), array_column($data, $i)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AnswerAdder | |
{ | |
private function addTheAnswer($x) | |
{ | |
return 42 + $x; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function computationWithAssumedKeys(array $array, array $necessaryKeys) { | |
$missingKeys = array_diff($necessaryKeys, array_keys($array)); | |
if (!empty($missingKeys)) { | |
$message = 'Computation failed due to missing key(s): ' . implode(', ', $missingKeys); | |
throw new \RuntimeException($message); | |
} | |
// compute... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative ((<$>)) | |
import Data.IntMap.Strict (IntMap) | |
import qualified Data.IntMap.Strict as IntMap | |
import Data.Function (on) | |
import Data.List (foldl', minimumBy, tails) | |
import Data.Maybe (fromMaybe) | |
import Data.Text (lines, splitOn, pack, unpack) | |
import Data.Text.IO (readFile) | |
import Prelude hiding (lines, readFile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mkTrie($elements, $all = true) { | |
$trie = array('' => false); | |
if(!$all) { | |
$tree = array('' => array('parent' => null, 'successors' => array())); | |
} | |
foreach($elements as $element) { | |
$key = ''; |