Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Matovu mtvbrianking

View GitHub Profile
@mtvbrianking
mtvbrianking / xml_get.php
Last active Oct 4, 2022
Get an item from xml by path.
View xml_get.php
<?php
// https://phpsandbox.io/n/steep-union-wnew-ndjxv
function xml_get(
SimpleXMLElement|string $xml,
string $path,
mixed $default = null
): mixed
{
@mtvbrianking
mtvbrianking / dto 1.php
Last active Sep 29, 2022
DTO Data Transfer Objects
View dto 1.php
<?php
use Spatie\DataTransferObject\DataTransferObject;
class Customer extends DataTransferObject
{
/** @var int|string $id */
public $id;
public string $alias;
public string $name;
@mtvbrianking
mtvbrianking / saveToEnvFile.php
Last active Sep 23, 2022
Update settings in dotenv file
View saveToEnvFile.php
<?php
function saveToEnvFile(string $dotEnv, string $pattern, string $label, ?string $value): bool
{
$readFrom = fopen($dotEnv, 'r');
$writeTo = tmpfile();
$isDirty = false;
while (!feof($readFrom)) {
$line = fgets($readFrom);
@mtvbrianking
mtvbrianking / multiple_ssh_setting.md
Created Aug 28, 2022 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts
View multiple_ssh_setting.md

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@mtvbrianking
mtvbrianking / command.md
Created Jul 9, 2022
Symfony Command Allow Extra Non Validated Options
View command.md
  namespace Symfony\Component\Console\Input;
  
  use Symfony\Component\Console\Exception\RuntimeException;
  
  class ArgvInput extends Input
  {
      protected function parse()
      {
@mtvbrianking
mtvbrianking / spatie-dto.php
Last active Jun 16, 2022
Spatie Data Transfer Object
View spatie-dto.php
<?php
// ..............................................
// V2
// ..............................................
use Spatie\DataTransferObject\DataTransferObject;
class Item extends DataTransferObject
{
View Multile SSH Setup.md

Generate ssh key pair

ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa_github -C "127.0.0.1"
ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa_gitlab -C "127.0.0.1"

Upload the *.pub to Github / Gitlab respectively.

Map ssh keys

@mtvbrianking
mtvbrianking / decrypt.sh
Last active Dec 28, 2021
OpenSSL Encryption & Decryption
View decrypt.sh
#!/bin/bash
encryptedPayloadFile=""
privateKeyFile=""
outputFile=""
function diy() {
cat <<EOF
openssl enc -base64 -A -d -in payload.cipher.base64 -out payload.cipher
@mtvbrianking
mtvbrianking / bash-command-arguments-options.txt
Created Dec 26, 2021
bash command stdin arguments options
View bash-command-arguments-options.txt
bash arguments options stdin flags
required
optional
./cmd arg1 agr2 --debug --output=test.txt
Args:
- arg1
@mtvbrianking
mtvbrianking / sign.sh
Last active Jan 20, 2022
OpenSSL Digital Signing
View sign.sh
#!/bin/bash
payload=""
privateKey=""
base64EncodedSignatureFile=""
function diy() {
cat <<EOF
printf %s "jdoe:23571113" > payload.txt