Skip to content

Instantly share code, notes, and snippets.

View ericdorsey's full-sized avatar

Eric Dorsey ericdorsey

View GitHub Profile
@ericdorsey
ericdorsey / FizzBuzz.go
Last active August 29, 2015 14:04
FizzBuzz in Go
package main
import "fmt"
//From http://blog.codinghorror.com/why-cant-programmers-program/
func main() {
for i := 1; i <= 100; i++ {
if (i % 3 == 0) && (i % 5 == 0) {
fmt.Println("FizzBuzz")
} else if i % 3 == 0 {
@ericdorsey
ericdorsey / FizzBuzz.js
Created July 24, 2014 04:05
Fizzbuzz in Javascript
//From http://blog.codinghorror.com/why-cant-programmers-program/
function FizzBuzz() {
for (var i = 1; i <= 100; i++) {
if ((i % 3 === 0) && (i % 5 === 0)) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("Fizz")
} else if (i % 5 === 0) {
console.log("Buzz")
} else {
@ericdorsey
ericdorsey / FizzBuzz.py
Last active August 29, 2015 14:04
FizzBuzz in Python
#From http://blog.codinghorror.com/why-cant-programmers-program/
def FizzBuzz():
for i in range(1,100):
if ((i % 3 == 0) and (i % 5 == 0)):
print "FizzBuzz"
elif (i % 3 == 0):
print "Fizz"
elif (i % 5 == 0):
print "Buzz"
else:
#!/usr/bin/expect -f
# usage: ./hubottest "hubot help"
spawn bin/hubot.coffee
sleep 3
expect "Hubot>"
send "hubot [lrange $argv 0 10]\n"
expect eo
@ericdorsey
ericdorsey / bottles2.py
Last active August 29, 2015 14:18
Infinite 99 Bottles w/ counter
import time
import sys
trips_to_store = 0
total_bottles_drank =0
bottles = 100
def final_stats(trips_to_store, total_bottles_drank):
if trips_to_store == 0:
print("\nNever went to the store for more beer.")
# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# Piece-by-Piece Explanation:
# the if condition makes sure we only screw with $PROMPT_COMMAND if we're in an iTerm environment
# iTerm happens to give each session a unique $ITERM_SESSION_ID we can use, $ITERM_PROFILE is an option too
# the $PROMPT_COMMAND environment variable is executed every time a command is run
# see: ss64.com/bash/syntax-prompt.html
@ericdorsey
ericdorsey / inception.py
Created April 19, 2015 02:15
Inception in Python
def inception(target_depth, current_depth=0, going_deeper=True):
if going_deeper == True:
if current_depth < target_depth:
current_depth += 1
if current_depth != target_depth:
print("Dream Level: {0}, going deeper..".format(current_depth))
elif current_depth == target_depth:
print("Dream Level: {0}, coming back up..".format(current_depth))
return inception(target_depth, current_depth, True)
elif current_depth == target_depth:
@ericdorsey
ericdorsey / hodor.py
Last active March 9, 2016 02:59
Hodor
import random
def hodor():
hodor_text = "Hodor"
rand_num_words = random.randrange(5, 9)
for i in range(rand_num_words):
if random.randrange(1, 4) == 3 and i != (rand_num_words - 1):
hodor_text += " hodor,"
else:
hodor_text += " hodor"

iPython "magic" %cpaste; assign to a variable

In iPython:

~ $ ipython
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.