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>
HTML
1 import System
2 import Foreign
3 import qualified Data.ByteString as B
4
5 main = do
6 w <- getArgs >>= readIO . head
7 let n = w `div` 8
8 loop_y = B.unfoldrN n (next_x w (2/fromIntegral w) n)
9
10 unfold x = case loop_y x of
11 (s, Nothing) -> B.putStr s
12 (s, Just x) -> B.putStr s >> unfold x
13
14 putStrLn ("P4\n"++show w++" "++show w)
15 unfold (T 1 0 0 (-1))
16
17 data T = T !Int !Int !Int !Double
18
19 next_x !w !iw !bw (T bx x y ci)
20 | y == w = Nothing
21 | bx == bw = Just (loop_x w x 8 iw ci 0, T 1 0 (y+1) (iw+ci))
22 | otherwise = Just (loop_x w x 8 iw ci 0, T (bx+1) (x+8) y ci)
23
24 loop_x !w !x !n !iw !ci !b
25 | x < w = if n == 0
26 then b
27 else loop_x w (x+1) (n-1) iw ci (b+b+v)
28 | otherwise = b `shiftL` n
29 where
30 v = fractal 0 0 (fromIntegral x * iw - 1.5) ci 50
31
32 fractal :: Double -> Double -> Double -> Double -> Int -> Word8
33 fractal !r !i !cr !ci !k
34 | r2 + i2 > 4 = 0
35 | k == 0 = 1
36 | otherwise = fractal (r2-i2+cr) ((r+r)*i+ci) cr ci (k-1)
37 where
38 (!r2,!i2) = (r*r,i*i)
Haskell
1 <?
2
3
4
5
6 function neat_r($arr, $return = false) {
7 $out = array();
8 $oldtab = " ";
9 $newtab = " ";
10
11 $lines = explode("\n", print_r($arr, true));
12
13 foreach ($lines as $line) {
14
15
16 if (substr($line, -5) != "Array") {
17 $line = preg_replace("/^(\s*)\[[0-9]+\] => /", "$1", $line, 1);
18 }
19
20
21 foreach (array(
22 "Array" => "",
23 "[" => "",
24 "]" => "",
25 " =>" => ":",
26 ) as $old => $new) {
27 $out = str_replace($old, $new, $out);
28 }
29
30
31 if (in_array(trim($line), array("Array", "(", ")", ""))) continue;
32
33
34 $indent = "";
35 $indents = floor((substr_count($line, $oldtab) - 1) / 2);
36 if ($indents > 0) { for ($i = 0; $i < $indents; $i++) { $indent .= $newtab; } }
37
38 $out[] = $indent . trim($line);
39 }
40
41 $out = implode("\n", $out) . "\n";
42 if ($return == true) return $out;
43 echo $out;
44 }
php
1 CREATE TABLE My_table(
2 my_field1 INT,
3 my_field2 VARCHAR(50),
4 my_field3 DATE NOT NULL,
5 PRIMARY KEY (my_field1, my_field2)
6 );
7
8 ALTER TABLE My_table ADD my_field4 NUMBER(3) NOT NULL;
9
10 GRANT SELECT, UPDATE
11 ON My_table
12 TO some_user, another_user;
13
14 REVOKE SELECT, UPDATE
15 ON My_table
16 FROM some_user, another_user;
17
18 SELECT Book.title,
19 COUNT(*) AS Authors
20 FROM Book JOIN Book_author
21 ON Book.isbn = Book_author.isbn
22 GROUP BY Book.title;
SQL
1 import java.io.*;
2 import java.util.*;
3
4 public class KeyboardIntegerReader {
5
6 public static void main (String[] args) throws java.io.IOException {
7 String s1;
8 String s2;
9 int num = 0;
10
11
12 BufferedReader br = new BufferedReader (new InputStreamReader (
13 System.in));
14
15 boolean cont = true;
16
17 while (cont)
18 {
19 System.out.print ("Enter an integer:");
20 s1 = br.readLine();
21 StringTokenizer st = new StringTokenizer (s1);
22 s2 = "";
23
24 while (cont && st.hasMoreTokens())
25 {
26 try
27 {
28 s2 = st.nextToken();
29 num = Integer.parseInt(s2);
30 cont = false;
31 }
32 catch (NumberFormatException n)
33 {
34 System.out.println("The value in \"" + s2 + "\" is not an integer");
35 }
36 }
37 }
38
39 System.out.println ("You entered the integer: " + num);
40 }
41 }
~/home/maurice/projects/wrench.java[+] unix JAVA 36/120
Java
1 function settable_event (table, key, value)
2 local h
3 if type(table) == "table" then
4 local v = rawget(table, key)
5
6 if v ~= nil then rawset(table, key, value); return end
7 h = metatable(table).__newindex
8 if h == nil then rawset(table, key, value); return end
9 else
10 h = metatable(table).__newindex
11 if h == nil then
12 error(···)
13 end
14 end
15 if type(h) == "function" then
16 h(table, key,value)
17 else h[key] = value
18 end
19 end
Lua
1 package Dancer::Handler::Standalone;
2
3 use strict;
4 use warnings;
5
6 use HTTP::Server::Simple::PSGI;
7 use base 'Dancer::Handler', 'HTTP::Server::Simple::PSGI';
8
9 use Dancer::HTTP;
~/home/maurice/fishsticks.pm[+] unix PERL 9/22
36 $dancer->run();
37 }
38 }
39
40 sub print_startup_info {
41 my $pid = shift;
42 my $ipaddr = setting('server');
43 my $port = setting('port');
44
45
46 setting('startup_info') or return;
47
48
49 print STDERR ">> Dancer $Dancer::VERSION server $pid listening " .
50 "on http://$ipaddr:$port\n";
51
52
53 foreach my $module ( grep { $_ =~ m{^Dancer/Plugin/} } keys %INC ) {
54 $module =~ s{/}{::}g;
~/home/maurice/fishsticks.pm[+] unix PERL 18/56
Perl
1
2 if [ -f /etc/bashrc ]; then
3 . /etc/bashrc
4 fi
5
6
7 alias grpe=grep
8 alias grep='grep --color --line-number'
9 alias vim="vim -p"
10 alias rebash="source ~/.bashrc"
11
12 alias install='sudo apt-get -y install'
13 alias search='apt-cache search'
14 alias purge='sudo apt-get purge'
15
16 export EDITOR=vim
17
18
19 shopt -s checkwinsize
20 PS1="\e[1;35m[\w] --- \@ \d \n$>\[\e[0m\]"
21 PS2="\e[1;35m->\[\e[0m\]"
22
23
24
25
26 define () {
27 lynx -dump "http://www.google.com/search?hl=en&q=define%3A+${1}" | grep -m 25 -w "*" | sed 's/;/ -/g' | cut -d- -f5 > /tmp/templookup.txt
28 if [[ -s /tmp/templookup.txt ]] ;then
29 until ! read response
30 do
31 echo "${response}"
32 done < /tmp/templookup.txt
33 else
34 echo "Sorry $USER, I can't find the term \"${1} \""
35 fi
36 rm -f /tmp/templookup.txt
37 }
38
39
40
41
42 extract () {
43 if [ -f $1 ] ; then
44 case $1 in
45 *.tar.bz2) tar xjf $1 ;;
46 *.tar.gz) tar xzf $1 ;;
47 *.bz2) bunzip2 $1 ;;
48 *.rar) rar x $1 ;;
49 *.gz) gunzip $1 ;;
50 *.tar) tar xf $1 ;;
51 *.tbz2) tar xjf $1 ;;
52 *.tgz) tar xzf $1 ;;
53 *.zip) unzip $1 ;;
54 *.Z) uncompress $1 ;;
55 *) echo "'$1' cannot be extracted via extract()" ;;
56 esac
57 else
58 echo "'$1' is not a valid file"
59 fi
60 }
61
Bash
1 \documentclass[12pt]{article}
2
3 \usepackage[option1, option2]{package}
4
5 \begin{document}
6
7
8 \section{Section head}
9 \subsection{Subsection head}
10
11 This is text, and the following is in-line mathematics:
12 $\mathrm{e}^{-\pi\matrhm{i}} = -1$.
13 A display-style equation is shown below:
14
15 \begin{equation}
16 E = mc^2
17 \end{equation}
18
19 \end{document}
~
~
~
~
~/home/maurice/docs/short.tex[+] unix PLAINTEX 14/19
LaTeX
1 integer :: my_seed
2 becomes
3 integer, optional :: my_seed
4 module ran_mod
5
6
7 contains
8 function ran1(my_seed)
9 use numz
10 implicit none
11 real(b8) ran1,r
12 integer, optional ,intent(in) :: my_seed
13 integer,allocatable :: seed(:)
14 integer the_size,j
15 if(present(my_seed))then
16 call random_seed(size=the_size)
17 allocate(seed(the_size))
18 do j=1,the_size
19 seed(j)=abs(my_seed)+(j-1)
20 enddo
21 call random_seed(put=seed)
22 deallocate(seed)
23 endif
24 call random_number(r)
25 ran1=r
26 end function ran1
27 end module
28
29 program darwin
30 use numz
31 use ran_mod
32
33 real(b8) x,y
34 x=ran1(my_seed=12345)
35 y=ran1()
36 write(*,*)x,y
37 x=ran1(12345)
38 y=ran1()
39 write(*,*)x,y
40 end program
Fortran
beta.py cheese.cc banana.py alpha.py
9 processFunc(str(getattr(object, method).__doc__)))
10 for method in methodList])
11
12 if __name__ == "__main__":
13 print info.cout
14
~
~
~
~/home/maurice/projects/banana.py[+] unix PYTHON 9/22
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 }
~
~
~
~/home/maurice/projects/cheese.cc[+] unix CPP 28/28
-- Keyword completion (^N^P) match 3 of 5
Vim Stuff
1
2 def triangles_v2f(scale):
3 if scale < 1.0:
4 return []
5 else:
6 data = triangles_v2f(scale / 2.0)
7 data.extend([
8 120 + scale, 120,
9 120 + scale, 120 + scale,
10 120, 120 + scale,
11 ])
12 return data
13
14 vbo_id = GLuint()
15
16 glGenBuffers(1, pointer(vbo_id))
17
18 data = (GLfloat*len(v2f))(*v2f)
19 v2f = triangles_v2f(200)
~
~
~
~
~/home/mau/proj/beta.py[+] unix PYTHON 14/28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1
2 def triangles_v2f(scale):
3 if scale < 1.0:
4 return []
5 else:
6 data = triangles_v2f(scale / 2.0)
7 data.extend([
8 100 + scale, 100,
9 100 + scale, 100 + scale,
10 100, 100 + scale,
11 ])
12 return data
13
14 vbo_id = GLuint()
15
16 glGenBuffers(1, pointer(vbo_id))
17
------------------------------------------------------
18 v2f = triangles_v2f(200)
19 data = (GLfloat*len(v2f))(*v2f)
~
~
~
~/home/mau/pro/alpha.py[+] unix PYTHON 28/28 |
Error detected while processing function DiffMerge_
Press ENTER or type a command to continue
Vim Diff
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 }
~/home/maurice/projects/example.cc[+] unix CPP 9/34
/ELEM
More Vim