Skip to content

Commit 516b4f4

Browse files
committed
moar moar moar
1 parent 53ebd28 commit 516b4f4

7 files changed

Lines changed: 77 additions & 6 deletions

File tree

v3/bottle_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@ def submit_matrix_problem():
104104

105105

106106
if __name__ == "__main__":
107-
run(host='localhost', port=8080, reloader=True)
107+
#run(host='localhost', port=8080, reloader=True)
108+
run(host='0.0.0.0', port=8003, reloader=True) # make it externally visible - DANGER this is very insecure since there's no sandboxing!

v4-cokapi/backends/ruby/notes.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,9 @@ gem install binding_of_caller
106106
Also see here for inspirational example code for getting a pretty backtrace:
107107
https://github.com/ko1/pretty_backtrace/blob/master/lib/pretty_backtrace.rb
108108

109+
110+
---
111+
2015-07-11
112+
113+
http://eli.thegreenplace.net/2006/04/18/understanding-ruby-blocks-procs-and-methods/
114+

v4-cokapi/backends/ruby/pg_logger.rb

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# - display class and instance variables
1414
# - display the 'binding' within a proc/lambda object, which represents
1515
# its closure
16-
# - for simplicity, maybe consolidate the '<main>' frame into the global
17-
# frame, so that 'locals' defined in main and methods appear together
1816
# - support gets() for user input using the restart hack mechanism
1917
# - user input stored in $_
2018
# - support 'include'-ing a module and bringing in variables into namespace
@@ -203,6 +201,8 @@ def self.iseq_local_variables iseq
203201
stack_entry = {}
204202
stack_entry['is_highlighted'] = false # set the last entry to true later
205203

204+
is_main = false
205+
206206
iseq = dc.frame_iseq(i)
207207
if !iseq
208208
# if you're, say, in a built-in operator like :/ (division)
@@ -225,7 +225,12 @@ def self.iseq_local_variables iseq
225225
STDERR.print 'frame_description: '
226226
STDERR.puts boc.frame_description
227227
STDERR.print 'frame_type: '
228-
STDERR.puts boc.frame_type # 'eval', 'method', 'block'
228+
STDERR.puts boc.frame_type # :eval, :method, :block
229+
230+
# special-case handling for the toplevel '<main>' frame
231+
if boc.frame_description == '<main>' && boc.frame_type == :eval
232+
is_main = true
233+
end
229234

230235
stack_entry['func_name'] = boc.frame_description # TODO: integrate 'frame_type' too?
231236

@@ -252,13 +257,26 @@ def self.iseq_local_variables iseq
252257

253258
stack_entry['ordered_varnames'] = lvs.map { |e| e.to_s }
254259
stack_entry['encoded_locals'] = lvs_val
255-
end
256260

257-
stack << stack_entry # only append on success
261+
# just fold everything into globals rather than creating a
262+
# separate (redundant) frame for '<main>'
263+
if is_main
264+
entry['ordered_globals'] += stack_entry['ordered_varnames']
265+
entry['globals'].update(stack_entry['encoded_locals'])
266+
end
267+
end
258268

269+
STDERR.puts '--- is_main: %s' % is_main
259270
STDERR.print '>>> ', loc, ' ', lvs, lvs_val
260271
STDERR.puts
261272
STDERR.puts
273+
274+
# no separate frame for main since its local variables were folded
275+
# into globals
276+
if !is_main
277+
stack << stack_entry
278+
end
279+
262280
end
263281
end
264282

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# from https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes
2+
class MyClass
3+
def self.some_method
4+
puts 'something'
5+
end
6+
end
7+
MyClass.some_method
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# from https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes
2+
3+
class MyClass
4+
@@value = 1
5+
def add_one
6+
@@value= @@value + 1
7+
end
8+
9+
def value
10+
@@value
11+
end
12+
end
13+
instanceOne = MyClass.new
14+
instanceTwo = MyClass.new
15+
puts instanceOne.value
16+
instanceOne.add_one
17+
puts instanceOne.value
18+
puts instanceTwo.value
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# adapted from http://eli.thegreenplace.net/2006/04/18/understanding-ruby-blocks-procs-and-methods/
2+
3+
def gen_times(factor)
4+
return Proc.new {|n| n*factor }
5+
end
6+
7+
times3 = gen_times(3)
8+
times5 = gen_times(5)
9+
10+
puts times3.call(12) #=> 36
11+
puts times5.call(5) #=> 25
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@x = 42
2+
@y = 'hello'
3+
puts @x
4+
puts @y
5+
@@classX = 'classy X'
6+
@@classY = 'classy Y'
7+
puts @@classX
8+
puts @@classY
9+
localX = 'local X'
10+
localY = 'local Y'

0 commit comments

Comments
 (0)