Skip to content

Instantly share code, notes, and snippets.

View kojiromike's full-sized avatar

Michael A. Smith kojiromike

View GitHub Profile
@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=(
@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 / 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:
#
<?php
/**
* Marker interface
*/
interface IConfig {}
/**
* An api sdk tool
*/
@kojiromike
kojiromike / install-0.1.0.php
Last active August 29, 2015 14:08
IIFE for setup script
<?php
/**
* What if we use an IIFE to guarantee scope control
* as well as aliasing and type hints for setup?
*/
// Standard setup script:
/**
* There's nothing really wrong with this, but you may wonder why alias $this to $installer.
* Also, what happens to the $entity var when the script is done?
<?php
class A {
public function A1 () {
return $this->A2();
}
protected function A2() {
return __METHOD__;
}
}

What are we talking about?

How does this Python function work?

def parenthesesMatch(par):
  lst = []
  push="<({[" 
  pop=">)}]"
 for l in par :
>>> x = 1
>>> def inc(x): x+=1
...
>>> inc(x)
>>> x
1
>>> inc(x)
>>> x
1
#!/bin/bash
# Testing what happens with storage with deleted containers
tcsetup() {
rm -rf /root/fstest
mkdir -p /root/fstest
}
tcinfo() {
du -s /mnt/sda1/var/lib/docker
#!/bin/bash
brewUses() {
brew list |
xargs -n1 -P6 bash -c 'echo "$1" $(brew uses --installed "$1")' _ |
awk '{
printf "%02d\033[1m %s \033[0m", NR, $1
for (i=2; i<NF; ++i) {
printf "\033[34mUSED BY:"
printf "\033[0m \033[4m%s", $i