Skip to content

Instantly share code, notes, and snippets.

@johnkary
Last active August 29, 2015 14:20
Show Gist options
  • Save johnkary/339f16638929b6d9ace7 to your computer and use it in GitHub Desktop.
Save johnkary/339f16638929b6d9ace7 to your computer and use it in GitHub Desktop.
Kansas City PHP User Group - Code Exercises

KC PHP User Group -- Code Exercises

  1. Install PHP, optionally with MySQL/Apache:
  2. Install Composer -- https://getcomposer.org/
  3. Choose an example problem from the below list you want to work on.
  4. Use libraries you've never used before!
  5. Regroup at the end to discuss what you tried and learned.

Beginner

Learn to use objects and namespaces

  • Invoke your program from the command-line.
  • Implement the FizzBuzz kata.
  • Use objects to model your code.
  • Make all classes use namespaces.

Do it with functions

  • Invoke your program from the command-line.
  • Implement the FizzBuzz kata using anonymous functions or closures.

Intermediate -- Ice cream store

Requirements

  1. Model an ice cream store that's giving away free ice cream for their grand opening
  2. List the available flavors
    • Alphabetical order
  3. Customer can place a new order
    • Size, flavor, customer name
    • After placing their order the Customer should receive an order number that will be called later
  4. Allow a customer to inquire about their order
    • Return their order number, size, flavor, customer name and status
  5. Allow a customer to cancel their order
    • Customer will give you their order number to cancel

Create a RESTful API for the requirements above using a micro framework

Create a command-line program for the requirements above

Intermediate -- FizzBuzz Kata

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 which are multiples of both three and five print "FizzBuzz"

FizzBuzz: Explore testing using PHPUnit

FizzBuzz: Explore testing using PHPSpec

FizzBuzz: Hard mode

  • Pretend the following PHP keywords do not exist. Implement FizzBuzz.
    • if/else
    • for
    • foreach
    • do/while
  • Ask John if you need hints :)

Advanced

Write a program using an event loop that simulates processing ice cream orders

Ice cream stand requirements:

  • Create an ice cream stand and staff it with 3 workers
  • Ability to add more workers while the store is open
  • Take in some new ice cream orders and fulfill them
  • Worker details
    • Preparing each flavor takes a variable time to prepare: number of letters in flavor name * 10 seconds. (i.e. chocolate === 90 seconds)
    • Ascribe certain workers with knowledge to only prepare certain flavors
      • Gracefully handle when a customer orders a flavor you don't have
  • Elastic features
    • How many orders per minute can you fulfill?
    • Can you add logic to intelligently call in new workers or prune workers according to work load?

Libraries for event loop in PHP:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment