Click the code, change the colors.
1 def dump_args(func):
2 "This decorator dumps out the arguments passed to a function before calling it"
3 argnames = func.func_code.co_varnames[:func.func_code.co_argcount]
4 fname = func.func_name
5 def echo_func(*args,**kwargs):
6 print fname, ":", ', '.join(
7 '%s=%r' % entry
8 for entry in zip(argnames,args) + kwargs.items())
9 return func(*args, **kwargs)
10 return echo_func
11
12 @dump_args
13 def f1(a,b,c):
14 print a + b + c
15
16 f1(1, 2, 3)
17
18 def precondition(precondition, use_conditions=DEFAULT_ON):
19 return conditions(precondition, None, use_conditions)
20
21 def postcondition(postcondition, use_conditions=DEFAULT_ON):
22 return conditions(None, postcondition, use_conditions)
23
24 class conditions(object):
25 __slots__ = ('__precondition', '__postcondition')
26
27 def __init__(self, pre, post, use_conditions=DEFAULT_ON):
28 if not use_conditions:
29 pre, post = None, None
30
31 self.__precondition = pre
32 self.__postcondition = post
33
Python
1
2 def power(x,n)
3 result = 1
4 while n.nonzero?
5 if n[0].nonzero?
6 result *= x
7 n -= 1
8 end
9 x *= x
10 n /= 2
11 end
12 return result
13 end
14
15 def f(x)
16 Math.sqrt(x.abs) + 5*x ** 3
17 end
18
19 (0...11).collect{ gets.to_i }.reverse.each do |x|
20 y = f(x)
21 puts "#{x} #{y.infinite? ? 'TOO LARGE' : y}"
22 end
23
24 COLORS = { :black => "000",
25 :red => "f00",
26 :green => "0f0",
27 :yellow => "ff0",
28 :blue => "00f",
29 :magenta => "f0f",
30 :cyan => "0ff",
31 :white => "fff" }
32
33 class String
34 COLORS.each do |color,code|
35 define_method "in_#{color}" do
36 "<span style=\"color: ##{code}\">#{self}</span>"
37 end
38 end
39 end
Ruby
1 #include "algostuff.hpp"
2 using namespace std;
3
4 bool bothEvenOrOdd (int elem1, int elem2)
5 {
6 return elem1 % 2 == elem2 % 2;
7 }
8
9 int main()
10 {
11 vector<int> coll1;
12 list<int> coll2;
13
14 float m = 40.0f;
15
16 INSERT_ELEMENTS(coll1,1,7);
17 INSERT_ELEMENTS(coll2,3,9);
18
19 PRINT_ELEMENTS(coll1,"coll1: \n");
20 PRINT_ELEMENTS(coll2,"coll2: \n");
21
22
23 if (equal (coll1.begin(), coll1.end(),
24 coll2.begin())) {
25 cout << "coll1 == coll2" << endl;
26 } TODO
27
28
29 if (equal (coll1.begin(), coll1.end(),
30 coll2.begin(),
31 bothEvenOrOdd)) {
32 cout << "even and odd elements correspond" << endl;
33 }
34 }
C++
1
2 var ralpha = /alpha\([^)]*\)/i,
3 ropacity = /opacity=([^)]*)/,
4
5 rupper = /([A-Z]|^ms)/g,
6 rnumpx = /^-?\d+(?:px)?$/i,
7 rnum = /^-?\d/,
8 rrelNum = /^([\-+])=([\-+.\de]+)/,
9
10 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
11 cssWidth = [ "Left", "Right" ],
12 cssHeight = [ "Top", "Bottom" ],
13 curCSS,
14
15 getComputedStyle,
16 currentStyle;
17
18 jQuery.fn.css = function( name, value ) {
19
20 if ( arguments.length === 2 && value === undefined ) {
21 return this;
22 }
23
24 return jQuery.access( this, name, value, true, function( elem, name, value ) {
25 return value !== undefined ?
26 jQuery.style( elem, name, value ) :
27 jQuery.css( elem, name );
28 });
29 };
Javascript
1
2 <html>
3 <head>
4 <title>Name Submission</title>
5 <meta name="author" content="Raoul Duke">
6 <script type="text/javascript" src="jquery.js"></script>
7 <link rel="stylesheet" type="text/css" href="name.css">
8 </head>
9
10 <body>
11 <h1> Submit your Name here! </h1>
12 <h3> We'll get more information on the following pages..</h3>
13 <form name="input" action="html_form_action.php" method="get">
14 First name > <input type="text" name="FirstName" value="Average" /><br />
15 Last name: > <input type="text" name="LastName" value="Redditor" /><br />
16 <input type="submit" value="Submit" />
17 </form>
18 <p class="standard" >Click "Submit" to continue..</p>
19
20 <h4>A nested List:</h4>
21 <ul>
22 <li>Coffee & Tea</li>
23 <li>Tea
24 <ul>
25 <li>Black tea</li>
26 <li>Green tea
27 <ul>
28 <li>China</li>
29 <li>Africa</li>
30 </ul>
31 </li>
32 </ul>
33 </li>
34 <li>Milk</li>
35 </ul>
36
37 </body>
38 </html>