#######
# ruby 1.9 examples
#######

%i(this is an array of symbols)
%I(this is too, but with #{@interpolation})
hash = { answer: 42 }
link_to 'new', new_article_path, class: 'btn'
# not a symbol
a ? b:c

########
# 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( ! $ % # )

##################################################################
# HEREDOCS
foo(<<-A, <<-B)
this is the text of a
A
and this is the text of b
B

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


##################################################################
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]


#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

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'

__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, 0313	W. Reisig
 VL	Do	09-11	wöch.	RUD 26, 0313	
 UE	Di	11-13	wöch.	RUD 26, 0313	
 PR	Di	13-15	wöch.	RUD 26, 0313	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, 1303	J. Köbler
 VL	Do	09-11	wöch.	RUD 26, 1305	
 UE	Do	11-13	wöch.	RUD 26, 1305	


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, 1308	M. Malek
VL	Do	09-11	wöch.	RUD 26, 1308
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, 1307	M. Grohe 
