Skip to content

Instantly share code, notes, and snippets.

View kojiromike's full-sized avatar

Michael A. Smith kojiromike

View GitHub Profile
<?php
class CaseMadness {
public function __call($m, $a) {
if ($m === 'callMe') {
return $this->callBob($a);
}
}
function callBob($a) {
from collections import deque
last3 = deque(maxlen=3)
def pings():
while True:
yield timepassed() * 17000 # Assume timepassed is updated somehow
# This may seem not D.R.Y., but there are only three…
ping = next(pings) # ;) Who knows how the pings are gotten
print("Current average: " + ping) # avg = ping/1
from collections import defaultdict
def person_to_club(_file):
result = defaultdict(list)
with open(_file) as memberships:
for line in filter(None, (l.strip() for l in memberships)):
if ',' in line:
key = line
else:
result[key].append(line)
return result
@kojiromike
kojiromike / gist:9796486
Created March 26, 2014 23:47
Someone's homework
#/!bin/bash
#
#Menunix - Bash
#
#Usage: menunixb
options=(
'List Files'
"Display today's date and time"
'Check whether a file is a directory or not'
#!/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]=$!
@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,

@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: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: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
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)