Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric Dorsey ericdorsey

View GitHub Profile
@ericdorsey
ericdorsey / FizzBuzz.go
Last active Aug 29, 2015
FizzBuzz in Go
View FizzBuzz.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 Jul 24, 2014
Fizzbuzz in Javascript
View FizzBuzz.js
//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 Aug 29, 2015
FizzBuzz in Python
View FizzBuzz.py
#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:
View hubottest
#!/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 Aug 29, 2015
Infinite 99 Bottles w/ counter
View bottles2.py
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.")
View current-dir-in-iterm-tab-title.sh
# 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 Apr 19, 2015
Inception in Python
View inception.py
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:
View hodor.py
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"
View ipython_cpaste.md

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.