Skip to content

Instantly share code, notes, and snippets.

View kojiromike's full-sized avatar

Michael A. Smith kojiromike

View GitHub Profile
<?php
/**
* Marker interface
*/
interface IConfig {}
/**
* An api sdk tool
*/
@kojiromike
kojiromike / randpass
Created September 22, 2014 14:08
Generate random passwords on a POSIX system
#!/bin/bash
##
# Generate a random password on a UNIX system.
#
# See the regex or re_format documentation for the syntax of
# "chars".
#
# Example:
#
@kojiromike
kojiromike / gist:dc9c914194a4c234446e
Last active August 29, 2015 14:06
Dealing with unwieldy filenames in the shell
$ printf -v filename '"%s" - "%s".epub' "Alice's Adventures in Wonderland" 'Carrol, Lewis'
$ printf '[%s]\n' "$filename"
["Alice's Adventures in Wonderland" - "Carrol, Lewis".epub]
$ >> "$filename"
$ ls
"Alice's Adventures in Wonderland" - "Carrol, Lewis".epub
$ for f in *; do printf '[%s]\n' "$f"; done
["Alice's Adventures in Wonderland" - "Carrol, Lewis".epub]
@kojiromike
kojiromike / gist:2229461e006c53252b89
Created August 24, 2014 20:45
On-demand mysql setup/teardown for magento testing.
#!/bin/bash
(
if mkdir -p mysql/data && cd mysql; then
[[ -f mysql.pid ]] && kill $(<mysql.pid)
client_opts=(
--no-defaults
--socket="$db_sock"
)
server_opts=(
In file included from /private/var/folders/dh/tb2vknxn0tn1zz18jqgb13wm0000gp/T/nix-build-php-5.4.31.drv-0/php-5.4.31/main/php.h:38:0,
from /private/var/folders/dh/tb2vknxn0tn1zz18jqgb13wm0000gp/T/nix-build-php-5.4.31.drv-0/php-5.4.31/ext/readline/readline.c:27:
/private/var/folders/dh/tb2vknxn0tn1zz18jqgb13wm0000gp/T/nix-build-php-5.4.31.drv-0/php-5.4.31/ext/readline/readline.c: In function 'zif_readline_info':
/private/var/folders/dh/tb2vknxn0tn1zz18jqgb13wm0000gp/T/nix-build-php-5.4.31.drv-0/php-5.4.31/ext/readline/readline.c:251:38: error: 'rl_mark' undeclared (first use in this function)
add_assoc_long(return_value,"mark",rl_mark);
^
/private/var/folders/dh/tb2vknxn0tn1zz18jqgb13wm0000gp/T/nix-build-php-5.4.31.drv-0/php-5.4.31/Zend/zend_API.h:383:92: note: in definition of macro 'add_assoc_long'
#define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key)+1, __n)
@kojiromike
kojiromike / gist:a2286d74b480818e06e5
Created July 24, 2014 16:55
even function from idris tutorial
even : Nat -> Bool
even Z = True
even (S k) = odd k
where
odd Z = False
odd (S k) = even k
@kojiromike
kojiromike / gist:cfe1f08a3b0c7b203395
Created July 12, 2014 23:54
Show that globstar matches files in the working directory
19:53 ~ $ mkdir -p foo/bar
19:53 ~ $ cd foo
19:53 ~/foo $ touch xyzzy.x bar/quu.x
19:54 ~/foo $ shopt -s globstar
19:54 ~/foo $ echo **/*.x
bar/quu.x xyzzy.x
@kojiromike
kojiromike / gist:7e5c47296ecc8e082a64
Created July 10, 2014 16:45
My favorite thing not to see in a tested Magento extension
<?php
if ($somethingIsWrong) {
Mage::throwException('oh noes');
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
@kojiromike
kojiromike / gist:494a7995695495b8d2dd
Last active August 29, 2015 14:02
Things I think the "Disable Modules Output" screen is useful for in Magento
  1. Being able to see effectively installed modules. Sometimes a module is unexpectedly installed (or not) and you want to be sure. If it's listed in this screen, you know it's installed.
  2. Being able to disable the frontend rendering of a module without turning off its code. This is useful when a module is a tight dependency or when you just temporarily want to shut something up. ;) I think it would be clearer if this feature were named something different, but naming things is a hard problem.
  3. Being able to enumerate all the modules. This differs from #1 in that it lets you get a general idea of the modules on a particular system (for example a production system) without needing shell access or taking any risky actions. (That said, being able to view installed modules shouldn't necessarily be the same permission as being able to disable their output.)

I know Magento 2 is working hard to strip out unnecessary tight dependencies between modules in core,

#!/bin/bash
# You could use array indices with any version of bash:
declare -a processes
filenames=( dir/* )
for filenum in "${!filenames[@]}"; do
filename=${filenames[filenum]}
run_step1 "$filename" > "${filename}.out" &
processes[filenum]=$!