Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class SudokuPuzzleWindowController < NSWindowController
attr_accessor :cell_4_0, :cell_4_1, :cell_4_2, :cell_4_3, :cell_4_4, :cell_4_5, :cell_4_6, :cell_4_7, :cell_4_8
attr_accessor :cell_5_0, :cell_5_1, :cell_5_2, :cell_5_3, :cell_5_4, :cell_5_5, :cell_5_6, :cell_5_7, :cell_5_8
attr_accessor :cell_6_0, :cell_6_1, :cell_6_2, :cell_6_3, :cell_6_4, :cell_6_5, :cell_6_6, :cell_6_7, :cell_6_8
attr_accessor :cell_7_0, :cell_7_1, :cell_7_2, :cell_7_3, :cell_7_4, :cell_7_5, :cell_7_6, :cell_7_7, :cell_7_8
attr_accessor :cell_8_0, :cell_8_1, :cell_8_2, :cell_8_3, :cell_8_4, :cell_8_5, :cell_8_6, :cell_8_7, :cell_8_8
attr_accessor :cell_7_0, :cell_7_1, :cell_7_2, :cell_7_3, :cell_7_4, :cell_7_5, :cell_7_6, :cell_7_7, :cell_7_8
attr_accessor :cell_8_0, :cell_8_1, :cell_8_2, :cell_8_3, :cell_8_4, :cell_8_5, :cell_8_6, :cell_8_7, :cell_8_8

def puzzle
cells = []
0.upto(8) do |x|
Expand Down Expand Up @@ -49,7 +49,7 @@ def next_state(state, x, y)
state[x][y] = 0
false
end

def valid_cell?(state, x, y)
# check in col and row
0.upto(8) do |i|
Expand All @@ -68,11 +68,11 @@ def valid_cell?(state, x, y)

true
end

def solve(sender)
pp puzzle
$count = 0
next_state(@puzzle, 0, 0)
next_state(@puzzle, 0, 0)
pp "Solved in #{$count} steps"
pp puzzle
end
Expand Down
4 changes: 2 additions & 2 deletions 360macdev-Denver-2010/SudokuSolverRB/Tests/stub_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class SimpleTest < Test::Unit::TestCase
def setup
puts 'setup called'
end

def teardown
puts 'teardown called'
end

def test_fail
assert false, 'Assertion was false.'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Application

include HotCocoa

def start
application :name => "Testruby" do |app|
app.delegate = self
Expand All @@ -16,27 +16,27 @@ def start
end
end
end

# file/open
def on_open(menu)
end
# file/new

# file/new
def on_new(menu)
end

# help menu item
def on_help(menu)
end

# This is commented out, so the minimize menu item is disabled
#def on_minimize(menu)
#end

# window/zoom
def on_zoom(menu)
end

# window/bring_all_to_front
def on_bring_all_to_front(menu)
end
Expand Down
2 changes: 1 addition & 1 deletion 360macdev-Denver-2010/TestRuby/config/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ version: "1.0"
icon: resources/HotCocoa.icns
resources:
- resources/**/*.*
sources:
sources:
- lib/**/*.rb
16 changes: 8 additions & 8 deletions 360macdev-Denver-2010/TestRuby/lib/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Application

include HotCocoa

def start
application :name => "Testruby" do |app|
app.delegate = self
Expand All @@ -16,27 +16,27 @@ def start
end
end
end

# file/open
def on_open(menu)
end
# file/new

# file/new
def on_new(menu)
end

# help menu item
def on_help(menu)
end

# This is commented out, so the minimize menu item is disabled
#def on_minimize(menu)
#end

# window/zoom
def on_zoom(menu)
end

# window/bring_all_to_front
def on_bring_all_to_front(menu)
end
Expand Down
18 changes: 9 additions & 9 deletions nsconf2011/CoreDataSample/MainWindowController.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
class MainWindowController < NSWindowController

attr_accessor :number_label

def windowDidLoad

puts "Window: #{self.window}"
self.window.title = "My Sample Core Data Application"

end

def createObject(sender)
person = Person.createEntity #magicalrecord helper

person.first_name = "first name: #{count}"
person.last_name = "last name: #{count}"
person.age = (rand * 100).round

NSManagedObjectContext.defaultContext.save #magicalrecord helper

count = Person.numberOfEntities

self.number_label.stringValue = count.to_s
end

def managedObjectContext
NSManagedObjectContext.defaultContext
end
Expand Down
2 changes: 1 addition & 1 deletion nsconf2011/CoreDataSample/SampleAppDelegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def applicationDidFinishLaunching(notification)
wc.window.makeKeyAndOrderFront(self)

end

end
2 changes: 1 addition & 1 deletion nsconf2011/CoreDataSample/SampleDataModel/_Person.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ - (PersonID*)objectID {

+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];

if ([key isEqualToString:@"ageValue"]) {
NSSet *affectingKey = [NSSet setWithObject:@"age"];
keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
Expand Down
4 changes: 2 additions & 2 deletions nsconf2011/CoreDataSample/Tests/stub_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class SimpleTest < Test::Unit::TestCase
def setup
puts 'setup called'
end

def teardown
puts 'teardown called'
end

def test_fail
assert false, 'Assertion was false.'
end
Expand Down
26 changes: 13 additions & 13 deletions nsconf2011/mandelbrot/MandelbrotView.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,52 @@
require 'dispatch'

class MandelbrotView < NSView

def awakeFromNib
@max_iterations = 1000
@scale = 1.4
end

def drawRect(rect)

self.computeMandelbrotInRect(rect, atLocation:[-1,0], scale:@scale)

end

def computeMandelbrotAtPoint(point, center:center, inRect:bounds, iterations:iterations, scale:scale)

xscaled = point[0]/(bounds.size.width/scale) + (center[0] - scale/2.0)
yscaled = point[1]/(bounds.size.height/scale) + (center[1] - scale/2.0)

x = xscaled
y = yscaled

(0..iterations).each { |i|
# puts "x #{x} y #{y} -> iteration #{i}"
return i if (x ** 2 + y ** 2) > 4

xtemp = x ** 2 - y ** 2 + xscaled
y = 2 * x * y + yscaled
x = xtemp
}
iterations

end

def selectColor(value)
colorValue = value / @max_iterations
color = NSColor.colorWithCalibratedWhite(colorValue, alpha:1)
color.set
end

def computeMandelbrotInRect(plane, atLocation:location, scale:scale)
context = NSGraphicsContext.currentContext.graphicsPort

startTime = Time.now
puts "Starting draw #{startTime}"
(location[1]..plane.size.height).each do |y|
(location[0]..plane.size.width).each do |x|

value = computeMandelbrotAtPoint([x, y], center:location, inRect:plane, iterations:@max_iterations, scale:@scale )

selectColor value
Expand All @@ -63,7 +63,7 @@ def computeMandelbrotInRect(plane, atLocation:location, scale:scale)
end
endTime = Time.now
puts "Ended draw #{endTime}: took #{endTime - startTime} seconds"

end

end
4 changes: 2 additions & 2 deletions nsconf2011/mandelbrot/Tests/stub_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class SimpleTest < Test::Unit::TestCase
def setup
puts 'setup called'
end

def teardown
puts 'teardown called'
end

def test_fail
assert false, 'Assertion was false.'
end
Expand Down