1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
|
#######
# ruby 1.9 examples
#######
class Random
RANDOM_VAR = 1
RANDOM_2 = 2
RANDOM_3 = 3
end
state :foo do
rule %r(/) do
token Operator
goto :expr_start
end
rule(//) { goto :method_call_spaced }
end
state :foo do
rule %r(/), Thing
end
%i(this is an array of symbols)
%I(this is too, but with #{@interpolation})
hash = { answer: 42, special?: true }
link_to 'new', new_article_path, class: 'btn'
########
# Ternaries
########
# NB [jneen]: MRI ruby actually has different parsing behavior depending on
# ~what variables are defined~, which we can't know in a highlighting context.
# So... we're going to be wrong here, sometimes. Whatever. These cases look
# okay though, but if they break I don't care a whole lot, because Ruby itself
# doesn't parse them consistently.
a ? b::c : :d # parsed as (a) ? (b::c) : (:d)
a ? b : :c # parsed as (a) ? (b) : (:c)
a ? b:c # parsed as (a) ? (b) : (c)
a ? :b : :c # parsed as (a) ? (:b) : (:c)
a ? :b :c # parsed as (a) ? (:b) : (c)
a ?b:c # parsed as (a) ? (b) : (c)
a ?b :c # parsed as (a) ? (b) : (c)
(a) ? b : c # parsed as (a) ? (b) : (c)
(a) \ # parsed as (a) ? (:b) : (:c)
? :b \
: :c
(a) ? # parsed as (a) ? (:b) : (:c)
:b :
:c
a # parsed as (a) ? (b) : (c)
? b
: c
?????:?? # parsed as (??) ? (??) : (??)
//?//:// # parsed as (//) ? (//) : (//)
method_that_takes_a_char ?b
cond??b::c : d
a?b :c # parsed as a? (b) (:c), syntax error for missing comma
a?b:c # parsed as a?(b: c), b is a symbol
a/1 # comment
a / b # comment
a /1 \r[egex]\//
a/ b #comment
x.a / 1 # comment
Foo::a / 3 + 4
########
# Keywords that may be immediately followed by an opening
# parenthesis
########
# defined?
return if defined? Rouge
return unless defined?(Foobar)
# super
class Beta < Alpha
def gamma(msg)
super
@msg = msg
end
end
class Bar < Foo
def log(msg)
super()
end
end
class Ipsum < Lorem
def dolor(txt)
super(txt)
end
end
########
# Various types of class definitions
########
# Singleton class definition
module Table
module Row
DEFAULTS = { cell_width: 80, cell_height: 60 }
class << self
def styles hsh
hsh.merge DEFAULTS
end
end
end
end
# Nested class name
module Table
module Row
class Cell < Table::Block
WIDTH = TABLE::ROW::styles[:cell_width]
def text string, width = WIDTH
string.center width
end
end
end
end
# Compact class name
class Table::Row::Cell < Table::Block
WIDTH = TABLE::ROW::styles[:cell_width]
def text string, width = WIDTH
string.center width
end
end
########
# The popular . :bow:
########
# It appears in Floats
2.3
1.2e3
1e23
1_2.3_4e5
# It appears in Range
1..10
# It can even appear thrice in a row!
10...100
########
# method calls
########
foo.bar
foo.bar.baz
foo.bar(123).baz()
foo.
bar
foo
.bar()
.baz
foo.
bar
foo.
bar().
baz
########
# function definitions
########
class (get_foo("blub"))::Foo
def (foo("bar") + bar("baz")).something argh, aaahaa
42
end
end
def -@
0 - self
end
class get_the_fuck("out")::Of::My
def parser_definition
ruby!
end
end
###############
# General
###############
a.each{|el|anz[el]=anz[el]?anz[el]+1:1}
while x<10000
#a bis f dienen dazu die Nachbarschaft festzulegen. Man stelle sich die #Zahl von 1 bis 64 im Binärcode vor 1 bedeutet an 0 aus
b=(p[x]%32)/16<1 ? 0 : 1
(x-102>=0? n[x-102].to_i : 0)*a+(x-101>=0?n[x-101].to_i : 0)*e+n[x-100].to_i+(x-99>=0? n[x-99].to_i : 0)*f+(x-98>=0? n[x-98].to_i : 0)*a+
n[x+199].to_i*b+n[x+200].to_i*d+n[x+201].to_i*b
#und die Ausgabe folgt
g=%w{}
x=0
#leere regex
test //, 123
{staples: /\ASTAPLE?S?\s*[0-9]/i,
target: "^TARGET "}
while x<100
puts"#{g[x]}"
x+=1
end
puts""
sleep(10)
1E1E1
puts 30.send(:/, 5) # prints 6
# fun with class attributes
class Foo
def self.blub x
if not x.nil?
self.new
end
end
def another_way_to_get_class
self.class
end
end
# ruby 1.9 "call operator"
a = Proc.new { 42 }
a.()
"instance variables can be #@included, #@@class_variables\n and #$globals as well."
`instance variables can be #@included, #@@class_variables\n and #$globals as well.`
'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
/instance variables can be #@included, #@@class_variables\n and #$globals as well./mousenix
:"instance variables can be #@included, #@@class_variables\n and #$globals as well."
:'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
%'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
%q'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
%Q'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
%w'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
%W'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
%s'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
%r'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
%x'instance variables can be #@included, #@@class_variables\n and #$globals as well.'
#%W[ but #@0illegal_values look strange.]
%s#ruby allows strange#{constructs}
%s#ruby allows strange#$constructs
%s#ruby allows strange#@@constructs
%( hash mark: # )
%r( hash mark: # )
%w( ! $ % # )
# this is modulo
board[i/w][i%w] == 'O'
puts [[x%w].reverse]
# this is a method that takes a list
def x(s) puts x end
x %w].]
# wordy logical operators
5.prime? or fail "something is terribly wrong"
chip = Bag.find_potato and chip.eat!
puts "odd" if not num % 2 == 0
##################################################################
# HEREDOCS
<<-CONTENT.strip_heredoc
D
E
CONTENT
foo(<<-A, <<-B)
this is the text of a
A
and this is the text of b
B
<<~END
This is a Ruby 2.3 stripped heredoc
END
a = <<"EOF"
This is a multiline #$here document
terminated by EOF on a line by itself
EOF
a = <<'EOF'
This is a multiline #$here document
terminated by EOF on a line by itself
EOF
b=(p[x] %32)/16<1 ? 0 : 1
<<""
#{test}
#@bla
#die suppe!!!
\xfffff
super <<-EOE % [
foo
EOE
<<X
X
X "foo" # This is a method call, heredoc ends at the prev line
%s(uninter\)pre\ted) # comment here
%q(uninter\)pre\ted) # comment here
%Q(inter\)pre\ted) # comment here
:"inter\)pre\ted" # comment here
:'uninter\'pre\ted' # comment here
%q[haha! [nesting [rocks] ! ] ] # commeht here
%(a #{interpolation_variable} b)
%Q(a #{interpolation_variable} b)
##################################################################
class NP
def initialize a=@p=[], b=@b=[]; end
def +@;@b<<1;b2c end;def-@;@b<<0;b2c end
def b2c;if @b.size==8;c=0;@b.each{|b|c<<=1;c|=b};send(
'lave'.reverse,(@p.join))if c==0;@p<< c.chr;@b=[] end
self end end ; begin _ = NP.new end
# Regexes
/
this is a
mutliline
regex
/
this /is a
multiline regex too/
also /4
is one/
this(/
too
/)
# this not
2 /4
asfsadf/
foo[:bar] / baz[:zot]
=begin some comments go here
a comment, that should not
end
here
=end
#from: http://coderay.rubychan.de/rays/show/383
class Object
alias :xeq :`
def `(cmd, p2)
self.method(cmd.to_sym).call(p2)
end
end
p [1,2,3].`('concat', [4,5,6]) # => [1, 2, 3, 4, 5, 6]
p [1,2,3].`(:concat, [4,5,6]) # => [1, 2, 3, 4, 5, 6]
p "Hurra! ".`(:*, 3) # => "Hurra! Hurra! Hurra! "
p "Hurra! ".`('*', 3) # => "Hurra! Hurra! Hurra! "
# Leider geht nicht die Wunschform
# [1,2,3] `concat` [4,5,6]
class Object
@@infixops = []
alias :xeq :`
def addinfix(operator)
@@infixops << operator
end
def `(expression)
@@infixops.each{|op|break if expression.match(/^(.*?) (#{op}) (.*)$/)}
raise "unknown infix operator in expression: #{expression}" if $2 == nil
eval($1).method($2.to_sym).call(eval($3))
end
end
addinfix("concat")
p `[1,2,3] concat [4,5,6]` # => [1, 2, 3, 4, 5, 6]
# HEREDOC FUN!!!!!!!1111
foo(<<A, <<-B, <<C)
this is the text of a
A!!!!
A
and this is text of B!!!!!!111
B
and here some C
C
###################################
######
# testing the __END__ content and % as an operator
######
events = Hash.new { |h, k| h[k] = [] }
DATA.read.split(/\n\n\n\s*/).each do |event|
name = event[/^.*/].sub(/http:.*/, '')
event[/\n.*/m].scan(/^([A-Z]{2}\S*)\s*(\S*)\s*(\S*)(\s*\S*)/) do |kind, day, daytime, comment|
events[ [day, daytime] ] << [kind, name + comment]
end
end
foo = 3
foo %= 2
foo /= 10 # not a regex
conflicts = 0
events.to_a.sort_by do |(day, daytime),|
[%w(Mo Di Mi Do Fr).index(day) || 0, daytime]
end.each do |(day, daytime), names|
if names.size > 1
conflicts += 1
print '!!! '
end
print "#{day} #{daytime}: "
names.each { |kind, name| puts " #{kind} #{name}" }
puts
end
puts '%d conflicts' % conflicts
puts '%d SWS' % (events.inject(0) { |sum, ((day, daytime),)| sum + (daytime[/\d+$/].to_i - daytime[/^\d+/].to_i) })
string = % foo # strange. huh?
print "Escape here: \n"
print 'Dont escape here: \n'
# Unicode support
class ViệtNam
def chào(buổi)
câu_chào = {sáng: "Chào buổi sáng", chiều: "Chào buổi chiều"}
puts câu_chào[buổi]
end
end
việt_nam = ViệtNam.new
việt_nam.chào(:sáng)
__END__
Informatik und Informationsgesellschaft I: Digitale Medien (32 214)
Computer lassen ihre eigentliche Bestimmung durch Multimedia und Vernetzung erkennen: Es sind digitale Medien, die alle bisherigen Massen- und Kommunikationsmedien simulieren, kopieren oder ersetzen können. Die kurze Geschichte elektronischer Medien vom Telegramm bis zum Fernsehen wird so zur Vorgeschichte des Computers als Medium. Der Prozess der Mediatisierung der Rechnernetze soll in Technik, Theorie und Praxis untersucht werden. Das PR soll die Techniken der ortsverteilten und zeitversetzten Lehre an Hand praktischer Übungen vorführen und untersuchen.
VL Di 15-17 wöch. RUD 25, 3.101 J. Koubek
VL Do 15-17 wöch. RUD 25, 3.101
UE/PR Do 17-19 wöch. RUD 25, 3.101 J.-M. Loebel
Methoden und Modelle des Systementwurfs (32 223)
Gute Methoden zum Entwurf und zur Verifikation von Systemen sind ein Schlüssel für gute Software. Dieses Seminar betrachtet moderne Entwurfsmethoden.
VL Di 09-11 wöch. RUD 26, 0313 W. Reisig
VL Do 09-11 wöch. RUD 26, 0313
UE Di 11-13 wöch. RUD 26, 0313
PR Di 13-15 wöch. RUD 26, 0313 D. Weinberg
Komplexitätstheorie (32 229)
In dieser Vorlesung untersuchen wir eine Reihe von wichtigen algorithmischen Problemstellungen aus verschiedenen Bereichen der Informatik. Unser besonderes Interesse gilt dabei der Abschätzung der Rechenressourcen, die zu ihrer Lösung aufzubringen sind. Die Vorlesung bildet eine wichtige Grundlage für weiterführende Veranstaltungen in den Bereichen Algorithmen, Kryptologie, Algorithmisches Lernen und Algorithmisches Beweisen.
VL Di 09-11 wöch. RUD 26, 1303 J. Köbler
VL Do 09-11 wöch. RUD 26, 1305
UE Do 11-13 wöch. RUD 26, 1305
Zuverlässige Systeme (32 234)
Mit zunehmender Verbreitung der Computertechnologie in immer mehr Bereichen des menschlichen Lebens wird die Zuverlässigkeit solcher Systeme zu einer immer zentraleren Frage.
Der Halbkurs "Zuverlässige Systeme" konzentriert sich auf folgende Schwerpunkte: Zuverlässigkeit, Fehlertoleranz, Responsivität, Messungen, Anwendungen, Systemmodelle und Techniken, Ausfallverhalten, Fehlermodelle, Schedulingtechniken, Software/Hardware - responsives Systemdesign, Analyse und Synthese, Bewertung, Fallstudien in Forschung und Industrie.
Der Halbkurs kann mit dem Halbkurs "Eigenschaften mobiler und eingebetteter Systeme" zu einem Projektkurs kombiniert werden. Ein gemeinsames Projekt begleitet beide Halbkurse.
VL Di 09-11 wöch. RUD 26, 1308 M. Malek
VL Do 09-11 wöch. RUD 26, 1308
PR n.V.
Stochastik für InformatikerInnen (32 239)
Grundlagen der Wahrscheinlichkeitsrechnung, Diskrete und stetige Wahrscheinlichkeitsmodelle in der Informatik, Grenzwertsätze, Simulationsverfahren, Zufallszahlen, Statistische Schätz- und Testverfahren, Markoffsche Ketten, Simulated Annealing, Probabilistische Analyse von Algorithmen.
VL Mo 09-11 wöch. RUD 25, 3.101 W. Kössler
VL Mi 09-11 wöch. RUD 25, 3.101
UE Mo 11-13 wöch. RUD 25, 3.101
UE Mi 11-13 wöch. RUD 25. 3.101
Geschichte der Informatik Ausgewählte Kapitel (32 243)
VL Mi 13-15 wöch. RUD 25, 3.113 W. Coy
Aktuelle Themen der Theoretischen Informatik (32 260)
In diesem Seminar sollen wichtige aktuelle Veröffentlichungen aus der theoretischen Informatik gemeinsam erarbeitet werden. Genaueres wird erst kurz vor dem Seminar entschieden. Bei Interesse wenden Sie sich bitte möglichst frühzeitig an den Veranstalter.
SE Fr 09-11 wöch. RUD 26, 1307 M. Grohe
|