Upcoming SlideShare
×

# Too busy sharpening the saw

638 views

Published on

Slides from my presentation at Roots 2011. Watch the recording here: http://vimeo.com/24735626

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
638
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
6
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Too busy sharpening the saw

1. 1. Too BusySharpening the Saw
2. 2. I
3. 3. AM
4. 4. A
5. 5. LIAR
6. 6. !
7. 7. Move upwards tothe unimportant
8. 8. Try faking it
9. 9. The mostimportant thing is the thing most easily forgotten
10. 10. Be extravagant
11. 11. Bridges - build - burn
12. 12. Consider different fading systems
13. 13. Courage!
14. 14. # states def count_lines(code):init = 0 current_line_is_code = Falsecode = 1 line_count = 0slash = 2 current_state = initslash_star = 3 for c in code + n:slash_slash = 4 input = translate_input(c)star = 5 current_state, contains_code = state_table[current_state][input]string = 6 if contains_code:bs_string = 7 current_line_is_code = True if input == input_n and current_line_is_code:# inputs line_count += 1input_w = 0 current_line_is_code = Falseinput_n = 1 return line_countinput_l = 2input_slash = 3 ### debug output ###input_star = 4input_quote = 5 state_str = [init, code, /,/*, //, *, ", ]input_bs = 6 def input_str(input):def translate_input(input): if input in t: if input == *: return <space> return input_star elif input in nr: elif input == /: return <NL> return input_slash else: elif input == ": return < + input + > return input_quote elif input == : def count_lines_with_debug_output(code): return input_bs current_line_is_code = False elif input in t: i=0 return input_w line_count = 0 elif input in nr: current_state = init return input_n for c in code + n: else: print "n=================" return input_l print code[:i+1] + \$n print state_str[current_state], t, input_str(c), t, =>,T = Truef = False current_state, contains_code = state_table[current_state][translate_input(c)] if contains_code:# state_table[current_state][input] == (next_state, contains_code?) current_line_is_code = Truestate_table = [ if translate_input(c) == input_n and current_line_is_code: [(init, f), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, T)], line_count += 1 [(code, T), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, current_line_is_code = FalseT)], [(code, T), (init, T), (code, T), (slash_slash,f), (slash_star, f), (string, T), (code, print state_str[current_state], ((%s) % line_count)T)], i+=1 [(slash_star, f), (slash_star, f), (slash_star, f), (slash_star, f), (star, f), (slash_star, f), return line_count(slash_star, f)], [(slash_slash, f), (init, f), (slash_slash,f), (slash_slash,f), (slash_slash,f), (slash_slash, f), import sys(slash_slash, f)], if __name__ == __main__: [(slash_star, f), (slash_star, f), (slash_star, f), (init, f), (star, f), (string, T), (slash_star, code = sys.stdin.read()f)], print count_lines_with_debug_output(code) [(string, T), (string, T), (string, T), (string, T), (string, T), (init, T), (bs_string,T)], [(string, T), (string, T), (string, T), (string, T), (string, T), (string, T), (string,T)] ]
15. 15. # states def count_lines(code):init = 0 current_line_is_code = Falsecode = 1 line_count = 0slash = 2 current_state = initslash_star = 3 for c in code + n:slash_slash = 4 input = translate_input(c)star = 5 current_state, contains_code = state_table[current_state][input]string = 6 if contains_code:bs_string = 7 current_line_is_code = True if input == input_n and current_line_is_code:# inputs line_count += 1input_w = 0 current_line_is_code = Falseinput_n = 1 return line_countinput_l = 2input_slash = 3 ### debug output ###input_star = 4input_quote = 5 state_str = [init, code, /,/*, //, *, ", ]input_bs = 6 def input_str(input):def translate_input(input): if input in t: if input == *: return <space> return input_star elif input in nr: puts gets. elif input == /: return <NL> return input_slash else: elif input == ": return < + input + > return input_quote gsub(/(/*([^*]|[rn]|(*+([^*/]|[rn])))**+/)|(//.*)/,). elif input == : return input_bs elif input in t: def count_lines_with_debug_output(code): current_line_is_code = False i=0 gsub(/^s*\$/,).gsub(/n+/,"n").split(/n/).length-1 return input_w line_count = 0 elif input in nr: current_state = init return input_n for c in code + n: else: print "n=================" return input_l print code[:i+1] + \$n print state_str[current_state], t, input_str(c), t, =>,T = Truef = False current_state, contains_code = state_table[current_state][translate_input(c)] if contains_code:# state_table[current_state][input] == (next_state, contains_code?) current_line_is_code = Truestate_table = [ if translate_input(c) == input_n and current_line_is_code: [(init, f), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, T)], line_count += 1 [(code, T), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, current_line_is_code = FalseT)], [(code, T), (init, T), (code, T), (slash_slash,f), (slash_star, f), (string, T), (code, print state_str[current_state], ((%s) % line_count)T)], i+=1 [(slash_star, f), (slash_star, f), (slash_star, f), (slash_star, f), (star, f), (slash_star, f), return line_count(slash_star, f)], [(slash_slash, f), (init, f), (slash_slash,f), (slash_slash,f), (slash_slash,f), (slash_slash, f), import sys(slash_slash, f)], if __name__ == __main__: [(slash_star, f), (slash_star, f), (slash_star, f), (init, f), (star, f), (string, T), (slash_star, code = sys.stdin.read()f)], print count_lines_with_debug_output(code) [(string, T), (string, T), (string, T), (string, T), (string, T), (init, T), (bs_string,T)], [(string, T), (string, T), (string, T), (string, T), (string, T), (string, T), (string,T)] ]
16. 16. # states def count_lines(code):init = 0 current_line_is_code = Falsecode = 1 line_count = 0slash = 2 current_state = initslash_star = 3 for c in code + n:slash_slash = 4 input = translate_input(c)star = 5 current_state, contains_code = state_table[current_state][input]string = 6 if contains_code:bs_string = 7 current_line_is_code = True if input == input_n and current_line_is_code:# inputs line_count += 1input_w = 0 current_line_is_code = Falseinput_n = 1 return line_countinput_l = 2input_slash = 3 ### debug output ###input_star = 4input_quote = 5 state_str = [init, code, /,/*, //, *, ", ]input_bs = 6 What’s Happening?def translate_input(input): def input_str(input): if input in t: if input == *: return <space> return input_star elif input in nr: puts gets. elif input == /: return <NL> return input_slash else: elif input == ": return < + input + > return input_quote gsub(/(/*([^*]|[rn]|(*+([^*/]|[rn])))**+/)|(//.*)/,). elif input == : return input_bs elif input in t: def count_lines_with_debug_output(code): current_line_is_code = False i=0 gsub(/^s*\$/,).gsub(/n+/,"n").split(/n/).length-1 return input_w line_count = 0 elif input in nr: current_state = init return input_n for c in code + n: else: print "n=================" return input_l print code[:i+1] + \$n print state_str[current_state], t, input_str(c), t, =>,T = Truef = False current_state, contains_code = state_table[current_state][translate_input(c)] if contains_code:# state_table[current_state][input] == (next_state, contains_code?) current_line_is_code = Truestate_table = [ [(init, [(code, f), (init, T), (init, f), (code, f), (code, T), (slash, T), (slash, f), (code, f), (code, T), (string, T), (string, T), (code, T), (code, T)], if translate_input(c) == input_n and current_line_is_code: line_count += 1 current_line_is_code = False 10 TweetT)], [(code, T), (init, T), (code, T), (slash_slash,f), (slash_star, f), (string, T), (code, print state_str[current_state], ((%s) % line_count)T)], i+=1 [(slash_star, f), (slash_star, f), (slash_star, f), (slash_star, f), (star, f), (slash_star, f), return line_count(slash_star, f)], [(slash_slash, f), (init, f), (slash_slash,f), (slash_slash,f), (slash_slash,f), (slash_slash, f), import sys(slash_slash, f)], if __name__ == __main__: [(slash_star, f), (slash_star, f), (slash_star, f), (init, f), (star, f), (string, T), (slash_star, code = sys.stdin.read()f)], print count_lines_with_debug_output(code) [(string, T), (string, T), (string, T), (string, T), (string, T), (init, T), (bs_string,T)], [(string, T), (string, T), (string, T), (string, T), (string, T), (string, T), (string,T)] ]
17. 17. andersnorås i t ’s o n l y c o d e , m o m
18. 18. @anorasmail@andersnoras.comandersnoras.com