This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
# This script deletes the garbage files generated when compiling a | |
# latex document. Run it from the directory you would like cleaned | |
# up. Source documents (those ending with *.tex, *.bib, and *.sty) | |
# and outputs (e.g. postscript and pdf files) are not affected. | |
filelist = os.listdir(os.getcwd()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
noremap : ; | |
noremap ; : | |
set number | |
set background=dark | |
set textwidth=80 | |
set paste | |
set foldmethod=indent | |
set nofoldenable "dont fold by default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nums = [1, 2, 3] | |
nums.map { |num| num.even? } # => [false, true, false] | |
nums.map(&:even?) # => [false, true, false] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Be careful when referencing mutable objects | |
a = {} # => {} | |
b = a # => {} | |
a.object_id # => 70132601471180 | |
b.object_id # => 70132601471180 | |
a[:foo] = 'bar' # => "bar" | |
b # => {:foo=>"bar"} # Woah! | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Mutable objects as hash keys: probably a bad idea. | |
silly_array = ['fox', 'cow', 'moose'] | |
another_ref = silly_array | |
# These variable names refer to the same object | |
silly_array.object_id == another_ref.object_id # => true | |
# Even though it doesn't seem like a great idea, | |
# ruby will let us use mutable objects, like |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mymethod(&blk) #Expects a block argument | |
puts "Hello from inside mymethod." | |
puts "Your block returns #{blk.call}" | |
end | |
mymethod do | |
puts "Hello from a block." | |
puts "I was to_proc'd and then called like a proc object." | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mymethod2(prc) | |
puts "Hello from inside mymethod2." | |
puts "Calling the Proc object returns #{prc.call}" | |
end | |
prc = Proc.new { puts "I'm a proc." } | |
mymethod2(prc) | |
# Outputs: | |
# Hello from inside mymethod2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mymethod3(&blk) | |
puts "Hello from inside method 3" | |
yield | |
end | |
mymethod3 do | |
puts "I'm part of a block." | |
puts "I get evaluated by mymethod3 even" | |
puts "though a procified block is never" | |
puts "explicitly called by the method." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TreeNode | |
attr_accessor :parent, :children | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
@parent = nil | |
@children = [] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TreeNode | |
# ... omitted. | |
def dfs(target_value = nil, &blk) | |
# A (broken) first attempt at depth-first search | |
# with arbitrary search criteria defined by the | |
# block received. | |
return self if !blk.nil && blk.call(@value) | |
return self if @value == target_value | |
OlderNewer