<?php | |
// This version replaces the redundant code with a recursive call, but emits these errors: | |
// | |
// ERROR: InvalidReturnType - src/Filter/FilterTransformer.php:111:16 - The declared return type 'Kiosk\Filter\PriceRange|array<array-key, Kiosk\Filter\PriceRange|float>|float' for Kiosk\Filter\FilterTransformer::getPrice is incorrect, got 'Kiosk\Filter\PriceRange|array<int|string(max)|string(min), Kiosk\Filter\PriceRange|array<array-key, Kiosk\Filter\PriceRange|float>|float>|float' (see https://psalm.dev/011) | |
// * @return float|float[]|PriceRange|PriceRange[] | |
// | |
// ERROR: InvalidReturnStatement - src/Filter/FilterTransformer.php:130:16 - The inferred type 'array<int|string(max)|string(min), Kiosk\Filter\PriceRange|array<array-key, Kiosk\Filter\PriceRange|float>|float>' does not match the declared return type 'Kiosk\Filter\PriceRange|array<array-key, Kiosk\Filter\PriceRange|float>|float' for Kiosk\Filter\FilterTransformer::getPrice (see https://psalm.dev/128) | |
// return array_map( | |
// [$t |
<?php | |
$height = 20; | |
$width = 40; | |
$live_seeds = 20; | |
$delay = 1000000; | |
$empty_grid = fn(): array => array_fill(0, $height, array_fill(0, $width, false)); | |
$random_percent = fn(): float => rand(0, 100) / 100; |
<?php | |
/** | |
* Sample output: | |
* | |
* $ time php queens.php | |
* [ ][ ][ ][ ][ ][X][ ][ ] | |
* [ ][ ][X][ ][ ][ ][ ][ ] | |
* [ ][ ][ ][ ][ ][ ][X][ ] | |
* [ ][X][ ][ ][ ][ ][ ][ ] |
<?php | |
function jefferson(string $message) | |
{ | |
$letters = array_merge(range('a', 'z'), ['_']); | |
$numbers = range(1, 26); | |
$cipher = []; | |
foreach ($numbers as $number) { | |
$cipher[$number] = []; | |
foreach ($letters as $index => $letter) { |
alias ga="git add" | |
alias gai="git add --interactive" | |
alias gb="git branch" | |
alias gbd="git branch -D" | |
alias gc="git commit" | |
alias gca="git commit --amend" | |
alias gcm="git commit -m" | |
alias gco="git checkout" | |
alias gcob="git checkout -b" | |
alias gd="git diff" |
FROM ubuntu:14.04 | |
ENV DEBIAN_FRONTEND noninteractive | |
RUN apt-get -y update && apt-get -y install python3 python3-pip git | |
RUN pip3 install virtualenv | |
RUN virtualenv ~/venv | |
RUN ~/venv/bin/pip install -e git+https://github.com/jleclanche/fireplace.git#egg=fireplace | |
RUN . ~/venv/bin/activate ; cd ~/venv/src/fireplace && pip3 install -r requirements.txt && ./bootstrap.sh && ./setup.py install && py.test | |
RUN echo '. ~/venv/bin/activate ; cd ~' >> ~/.bashrc |
Let's imagine that you've got information for accessing several different databases you have to work with on a regular basis. Servers (e.g. mysql, pgsql, etc.), hostnames, ports, usernames, password files, database names, etc.
Let's also imagine that there are several programs you use on these databases regularly. If you use MySQL, this might include the mysql
CLI client, the mysqldump
utility, and liquibase
for versioning.
Manually typing these commands together with this database information is tedious. Managing shorthand shell functions for the same purpose also seems suboptimal.
What I want is a wrapper utility of sorts to which I can specify the program I want to run and the name of (or potentially a shorthand alias for) the database I want to run it on, and have it pull all other information from a configuration file I create to derive and run the resulting CLI command.
Here's a hypothetical example of such a file:
<?php | |
function PasswordGenerator($min = 1, $max = null) | |
{ | |
$ord = range(32, 126); | |
$chr = array_map('chr', $ord); | |
$first = reset($chr); | |
$last = end($chr); | |
$length = $min; | |
$password = array_fill(0, $length, $first); | |
$stop = array_fill(0, $length, $last); |