Skip to content

Instantly share code, notes, and snippets.

View kojiromike's full-sized avatar

Michael A. Smith kojiromike

View GitHub Profile
$ cat catchtest.php
<?php
interface FooFail {}
interface BarFail {}
class YesFail extends Exception implements FooFail, BarFail {}
class NoFail implements FooFail {}
try { throw new YesFail; }
catch (FooFail $e) { echo "Caught the foo\n"; }
@kojiromike
kojiromike / gist:bc353c64cd4be7552331
Last active August 29, 2015 14:24
Boot2Docker on xhyve

Xhyve Boot2Docker

I got boot2docker running on xhyve. Here's my startup script:

#!/bin/sh

KERNEL=boot2docker/vmlinuz64
INITRD=boot2docker/initrd.img
CMDLINE='earlyprintk=serial console=ttyS0 acpi=off user=docker'
@kojiromike
kojiromike / bogobuzz.php
Created April 30, 2015 21:07
BogoBuzz: FizzBuzz, but even dumber
<?php
/**
* BogoBuzz
*
* FizzBuzz, but randomly
*/
$seen = [];
while (count($seen) !== 100) {
$i = rand(1, 100);
@kojiromike
kojiromike / fizzbuzz.md
Last active February 18, 2016 02:02
Fizz Buzz

Fizz Buzz

The dumbest programming challenge

Please write a program that prints the numbers from 1 to 100, but for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers that are multiples of both three and five print "FizzBuzz".

You can do clever things with FizzBuzz. You can write it recursively, or use a stack. You can do better math, remembering that the LCM of three and five is fifteen. But here's the thing about FizzBuzz. Programmers get nervous in interviews and they forget the basics. They don't forget math, or the syntax of a for loop. I mean they forget how to deconstruct a programming problem. FizzBuzz has just enough crap in it that trying to write it in one step is foolish. Break the program down into its discrete functions.

Break the program down

#!/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
#!/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
>>> x = 1
>>> def inc(x): x+=1
...
>>> inc(x)
>>> x
1
>>> inc(x)
>>> x
1

What are we talking about?

How does this Python function work?

def parenthesesMatch(par):
  lst = []
  push="<({[" 
  pop=">)}]"
 for l in par :
<?php
class A {
public function A1 () {
return $this->A2();
}
protected function A2() {
return __METHOD__;
}
}
@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?