Skip to content

Instantly share code, notes, and snippets.

@mfdj
mfdj / angular_scope_inheritance_demo.html
Last active August 29, 2015 14:14
angular scope inheritance demo
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>scope inheritance</title>
</head>
<body>
<h3>Controller Scope Inheritance</h3>
<!-- PARENT -->
@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 / 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 / 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 / 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 / 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 / a-b
Last active April 17, 2016 06:09
_
| |__ ___ ___
| '_ \ / _ \/ _ \
| |_) | __/ __/
|_.__/ \___|\___|
@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 / 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