Skip to content

Instantly share code, notes, and snippets.

@mfdj
mfdj / mage2_module_scaffold.sh
Created May 24, 2016 00:18
shell function to scaffold a magento2 module
<< DOC
Usae:
mage2_module_scaffold <vendor> <module>
Note:
This command is destructive — it will ovewrite app/code/<vendor>/<module>/etc/module.xml
DOC
mage2_module_scaffold() {
local vendor=$1
@mfdj
mfdj / calcualte-total-milliseconds.sh
Created April 22, 2016 19:30
grep | awk | tr | past | bc
grep 'ms' $LOG_FILE | awk '{print $(NF-0)}' | tr -d '()ms' | paste -sd+ - | bc
@mfdj
mfdj / a-b
Last active April 17, 2016 06:09
_
| |__ ___ ___
| '_ \ / _ \/ _ \
| |_) | __/ __/
|_.__/ \___|\___|
@mfdj
mfdj / build_client_archive.sh
Last active April 8, 2016 18:02
Pre deploy client build example
#!/usr/bin/env bash
if ! command -v gulp > /dev/null; then
echo && echo "error: gulp required"
exit 1
fi
gulp build
if ! command -v md5sum > /dev/null; then
@mfdj
mfdj / javascript-closure-symbol-evaluation.js
Last active February 5, 2016 01:58
A very subtle detail of Javascript closures is understanding *when* a closed over symbol's value is read for use inside the closure body. Surprisingly the value isn't captured when the closure is defined, so the scope of the symbol can mutate the symbol at any point before the closure is called.
function makeProblems(count) {
var problems = [];
for (var i = 0; i < count; i++) {
var problematic = function(runId) {
console.log(runId + ' executed with i as: ' + i); // <-- `i` is bound to makeProblems scope
};
problems.push(problematic);
@mfdj
mfdj / expand_import_globs.sh
Last active January 31, 2016 20:59
Decoupling from rails-sass and asset-pipeline and moving to sassc
# assuming you have a root stylesheet like app/assets/stylesheets/application.scss you can easily generate all your import
# statements with a single line of BASH
# look in all of the sub-folders of app/assets/stylesheets/ for scss files
# find app/assets/stylesheets/*/* -name '*.scss'
# ignore the first 24 characters of the path (i.e. `app/assets/stylesheets/`)
# cut -c 24-
# create import statement for each file found
# awk '{print "@import \"" $1"\";"}'
# remove any distracting leading underscores from the filenames
@mfdj
mfdj / lazy_apm_install.sh
Last active December 3, 2015 23:10
atom package manager install is not lazy (it always does a fresh install of a package), but with some shell magic you can make it lazy
#!/usr/bin/env bash
apm_lazy_install() {
for package in $@; do
apm list | grep $package > /dev/null ||
apm install $pacakge
done
}
apm_lazier_install() {
@mfdj
mfdj / cdp.sh
Last active August 26, 2015 03:08
cdp function - dead simple approach to creating and visiting directory aliases
# directory where aliases are stored
export CDP_PATH=~/dotfiles/cdp_symlinks
# cdp --add <-- creates an alias of the current direcotry path, named for the current folder name
# cdp --add custom-name <-- same as above with custom-name
# cdp another-name <-- change into alias
# cdp --list <-- see all aliases available to cdp
# cdp --remove some-name <-- remove an alias
# cd `cdp --path` <-- change into the directory where aliases are stored
function cdp {
@mfdj
mfdj / rand_int.sh
Last active August 26, 2015 21:06
BASH random integer function using /dev/urandom
function rand_int {
local min=$1
local max=$2
# dd if=/dev/urandom bs=1 count=1 <-- grab a single 1-byte frame from /dev/urandom
# | od -An -vtu1 <-- convert raw-binary to a decimal
# | tr -d ' ' | tr -d "\n"` <-- trim spaces and line-breaks from output of od (gotta be better way)
local randByte=`dd if=/dev/urandom bs=1 count=1 2> /dev/null | od -An -vtu1 | tr -d ' ' | tr -d "\n"`
@mfdj
mfdj / console_methods.html
Last active August 25, 2015 21:59
browser console methods
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>console methods</title>
</head>
<body>
<script>
console.assert(1 === true, "assert 1 is strictly equal to true");
console.log({a: "eh", b: "bee"}, [1,2,4,8,16]);