Skip to content

Instantly share code, notes, and snippets.

@mfdj
mfdj / bash_function_mamp_files.sh
Last active August 4, 2020 18:26
Bash function to launch different MAMP Basic configuration files in your prefered text editor
# Usage:
# $ mamp
# $ mamp (apache|vhosts|hosts|php|mysql|a|v|h|p|m)
# $ mamp (error|e)
# $ mamp (error|e) (clear|apache|php|mysql|a|p|m)
# e.g. open php.ini: $ mamp php
# $ mamp p
# e.g. open apache error log: $ mamp error apache
# $ mamp e a
# Uses $EDITOR by default.
@mfdj
mfdj / php-testing_variable_existence_results.md
Last active January 6, 2022 15:14
shell script that tests various types for "existence" using isset, empty, is_null, count, if/else, ternary, strict equality with null, … — should be easy to add/remove values and tests.

Testing variable existence in php

Run the tests (code below): testing-variable-existence.php

Results Matrix

=== null is_null isset empty if/else ternary count > 0
$a; true true true
null true true true
@mfdj
mfdj / wildcard_ssl_certificate.sh
Last active October 29, 2022 11:08
Bash script that uses openssl to generate a wildcard certificate suitable for use in a local testing environment: not vetted for a production/public internet purposes. Usage: `$ ./wildcard.sh yourdomain.local` — generates a private key, certificate request, and ssl certificate.
#!/usr/bin/env bash
DOMAIN=$1
if [ -z "$DOMAIN" ]; then
echo -n 'Enter root domain (no www): '
read input_d
DOMAIN=$input_d
fi
@mfdj
mfdj / pwd-to-clipboard.sh
Created January 6, 2014 06:42
OSX/Bash one-liner to copy the working directory to the clipboard
pwd | tr -d '\n' | pbcopy
@mfdj
mfdj / symfony2_hello_world.sh
Last active January 3, 2016 20:29
Challenge: create a one-liner to install a custom "hello world" app using symfony2 standard, composer, git and standardish bash tools. Try it out — copy, paste, run: $ wget -O symfony2_hello_world.sh https://gist.github.com/mfdj/8515732/raw/87dc7c489fe6a8b1d632a2b21e411e6596116152/symfony2_hello_world.sh && chmod +x symfony2_hello_world.sh && ./…
#!/usr/bin/env bash
# Works partially with Symofny 2.5
# Works fully with Symfony 2.3 — 2.4
# Tested against Symfony: 2.5.0, 2.4.1, 2.3.9
# Usage:
# symfony2_hello_world.sh <optional: project folder> <optional: symfony version> <optional: domain name>
# Examples:
# symfony2_hello_world.sh
@mfdj
mfdj / openssl_ca_recipe.sh
Last active August 29, 2015 13:57
Generate multiple clean, workable local "mini Certificate Authorities" preconfigured to be good enough. Based on OpenSSL. Developed for Bash on OSX (should be pretty portable).
#!/usr/bin/env bash
function defaultinput()
{
local LABEL=$1
local DEFAULT=$2
local __return=$3
echo -n "$LABEL [$DEFAULT] "
read input_a
if [[ -z "$input_a" ]]; then
@mfdj
mfdj / colon_to_multiline.sh
Last active August 29, 2015 13:57
view $PATH (or any colon separated string) as a readable multiline output — tested on OSX bash
##### first attempt
# one-liner
echo $PATH | sed -e "s~:~\\`echo -e '\n\r'`~g"
# bash function
sep2ln()
{
local INPUT=$1
local SEPARATOR=$2
@mfdj
mfdj / .htaccess
Last active August 29, 2015 14:00
Adding HSTS headers to all responses when using php-fpm + mod_fastcgi using basic php or Symfony2
# add HTTP Strict Transport Security (HSTS) header to all *non-php* responses
# - mod_fastcgi apparently ignores mod_headers?
# - see: https://www.owasp.org/index.php/HTTP_Strict_Transport_Security
Header set Strict-Transport-Security "max-age=7776000"
@mfdj
mfdj / config.yml
Last active August 29, 2015 14:03
Extract database-related and other parameters from PagodaBox's environment — override parameters.yml and keep your secrets out of your repo
# file: app/config/config.yml
imports:
- { resource: parameters.yml }
- { resource: parameters_pagoda.php } # import after parameters.yml to override it's values
- { resource: security.yml }

Keybase proof

I hereby claim:

  • I am mfdj on github.
  • I am mfdj (https://keybase.io/mfdj) on keybase.
  • I have a public key whose fingerprint is A056 0C76 83D0 CD21 912A 34AB 45ED 067E 0D3B 9AC3

To claim this, I am signing this object: