Skip to content

Commit a93ac99

Browse files
committed
Improved peformance of bisection algorithm.
Improved performance of insertion algorithm.
1 parent a8aeb7e commit a93ac99

9 files changed

+552
-343
lines changed

ex.ruby.html

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
<link rel="stylesheet" href="jquery.syntax.css" type="text/css" media="screen" />
6+
<link rel="stylesheet" href="example.css" type="text/css" media="screen" />
7+
8+
<script src="jquery-1.4.1.js" type="text/javascript"></script>
9+
<script src="jquery.syntax.js" type="text/javascript" charset='utf-8'></script>
10+
<script src="jquery.syntax.cache.js" type="text/javascript" charset='utf-8'></script>
11+
12+
<script type="text/javascript" language="JavaScript">
13+
//<!--
14+
$(function() {
15+
$('pre.ruby').syntax({brush: 'ruby', layout: 'table', replace: true})
16+
})
17+
//-->
18+
</script>
19+
20+
</head>
21+
<body>
22+
<h1>Syntax: Ruby</h1>
23+
24+
<pre class="ruby">#!/usr/bin/env ruby
25+
26+
# Copyright (c) 2009 Samuel Williams. Released under the GNU GPLv3.
27+
#
28+
# This program is free software: you can redistribute it and/or modify
29+
# it under the terms of the GNU General Public License as published by
30+
# the Free Software Foundation, either version 3 of the License, or
31+
# (at your option) any later version.
32+
#
33+
# This program is distributed in the hope that it will be useful,
34+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
35+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36+
# GNU General Public License for more details.
37+
#
38+
# You should have received a copy of the GNU General Public License
39+
# along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.
40+
41+
require 'rubygems'
42+
43+
require 'rexec'
44+
require 'rexec/daemon'
45+
46+
require 'rubygems'
47+
require 'rubydns'
48+
49+
# To run this command, use the standard daemon syntax as root
50+
# ./daemon2.rb start
51+
52+
# You should be able to see that the server has dropped priviledges
53+
# # ps aux | grep daemon2.rb
54+
# daemon 16555 0.4 0.0 81392 2024 ?? S 3:35am 0:00.28 ruby ../test/daemon2.rb start
55+
56+
# Test using the following command
57+
# dig @localhost test.mydomain.org
58+
59+
# You might need to change the user name &quot;daemon&quot;. This can be a user name or a user id.
60+
RUN_AS = &quot;daemon&quot;
61+
62+
# UDP Socket does per packet reverse lookups unless this is set.
63+
UDPSocket.do_not_reverse_lookup = true
64+
65+
# We need to be root in order to bind to privileged port
66+
if RExec.current_user != &quot;root&quot;
67+
$stderr.puts &quot;Sorry, this command needs to be run as root!&quot;
68+
exit 1
69+
end
70+
71+
# The Daemon itself
72+
class Server &lt; RExec::Daemon::Base
73+
@@var_directory = File.dirname(__FILE__)
74+
75+
def self.run
76+
# Bind to port 53 (UDP)
77+
socket = UDPSocket.new
78+
socket.bind(&quot;0.0.0.0&quot;, 53)
79+
80+
# Drop priviledges
81+
RExec.change_user(RUN_AS)
82+
83+
# Don't buffer output (for debug purposes)
84+
$stderr.sync = true
85+
86+
# Use upstream DNS for name resolution (These ones are Orcon DNS in NZ)
87+
$R = Resolv::DNS.new(:nameserver =&gt; [&quot;60.234.1.1&quot;, &quot;60.234.2.2&quot;])
88+
89+
# Start the RubyDNS server
90+
RubyDNS::run_server(:listen =&gt; [socket]) do
91+
match(&quot;test.mydomain.org&quot;, :A) do |transaction|
92+
transaction.respond!(&quot;10.0.0.80&quot;)
93+
end
94+
95+
# Default DNS handler
96+
otherwise do |transaction|
97+
logger.info &quot;Passthrough: #{transaction}&quot;
98+
transaction.passthrough!($R)
99+
end
100+
end
101+
end
102+
end
103+
104+
# RExec daemon runner
105+
Server.daemonize</pre>
106+
107+
</body>
108+
</html>

example.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ <h1>Syntax Highlighting Example</h1>
3030

3131
<button id="highlight">Highlight</button>
3232

33-
<pre class="clang">#include &lt;iostream&gt; // std::out
33+
<pre class="clang">#include &lt;iostream&gt;
34+
/* Multi line c comment
35+
36+
Hello World
37+
*/
38+
39+
const char * s = "My name is computer!\n\n"
3440
int main (int argv, char ** argv) {
3541
return EXIT_SUCCESS;
3642
}

example2.html

Lines changed: 7 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
<link rel="stylesheet" href="jquery.syntax.css" type="text/css" media="screen" />
66
<link rel="stylesheet" href="example.css" type="text/css" media="screen" />
77

8-
<script src="jquery-1.4.1.js" type="text/javascript" charset="utf-8"></script>
8+
<script src="jquery-1.4.1.js" type="text/javascript"></script>
99

10-
<script src="jquery.syntax.js" type="text/javascript" charset="utf-8"></script>
10+
<script src="jquery.syntax.js" type="text/javascript"></script>
1111
<script src="jquery.syntax.cache.js" type="text/javascript" charset='utf-8'></script>
1212

13+
<script src="jquery.syntax.brush.clang.js" type="text/javascript"></script>
14+
<script src="jquery.syntax.layout.table.js" type="text/javascript"></script>
15+
16+
<link rel="stylesheet" href="jquery.syntax.layout.table.css" type="text/css" media="screen">
17+
1318
<script type="text/javascript" language="JavaScript">
1419
//<!--
1520
$(function() {
@@ -53,96 +58,6 @@ <h1>Syntax Highlighting Example</h1>
5358
return row + col * sz;
5459
}
5560

56-
template &lt;typename _ValueT, unsigned _R, unsigned _C, bool _ColumnMajor&gt;
57-
class Matrix {
58-
protected:
59-
enum { ColumnMajor = _ColumnMajor };
60-
enum { R = _R };
61-
enum { C = _C };
62-
63-
typedef _ValueT ValueT;
64-
65-
ValueT m_values[C*R];
66-
67-
public:
68-
const ValueT &amp; at (unsigned r, unsigned c) const
69-
{
70-
if (ColumnMajor)
71-
return m_values[columnMajorOffset(r, c, R)];
72-
else
73-
return m_values[rowMajorOffset(r, c, C)];
74-
}
75-
76-
ValueT &amp; at (unsigned r, unsigned c)
77-
{
78-
if (ColumnMajor)
79-
return m_values[columnMajorOffset(r, c, R)];
80-
else
81-
return m_values[rowMajorOffset(r, c, C)];
82-
}
83-
84-
void loadTestPattern ()
85-
{
86-
for (unsigned r = 0; r &lt; R; r += 1)
87-
for (unsigned c = 0; c &lt; C; c += 1)
88-
at(r, c) = (r+1) * 1000 + (c+1);
89-
}
90-
91-
void debug ()
92-
{
93-
using namespace std;
94-
95-
if (ColumnMajor)
96-
cout &lt;&lt; &quot;Column-Major Matrix &quot; &lt;&lt; &quot;(&quot; &lt;&lt; R &lt;&lt; &quot;,&quot; &lt;&lt; C &lt;&lt; &quot;)&quot; &lt;&lt; &quot; @ &quot; &lt;&lt; this &lt;&lt; endl;
97-
else
98-
cout &lt;&lt; &quot;Row-Major Matrix &quot; &lt;&lt; &quot;(&quot; &lt;&lt; R &lt;&lt; &quot;,&quot; &lt;&lt; C &lt;&lt; &quot;)&quot; &lt;&lt; &quot; @ &quot; &lt;&lt; this &lt;&lt; endl;
99-
100-
cout &lt;&lt; &quot;Memory Offset: &quot;;
101-
for (unsigned i = 0; i &lt; (R*C); i += 1)
102-
cout &lt;&lt; i &lt;&lt; &quot; &quot;;
103-
cout &lt;&lt; endl;
104-
105-
cout &lt;&lt; &quot; Values: &quot;;
106-
for (unsigned i = 0; i &lt; (R*C); i += 1)
107-
cout &lt;&lt; m_values[i] &lt;&lt; &quot; &quot;;
108-
cout &lt;&lt; endl;
109-
110-
cout &lt;&lt; &quot;Standard Mathematical Notation:&quot; &lt;&lt; endl;
111-
cout &lt;&lt; &quot; &quot;;
112-
for (unsigned c = 0; c &lt; C; c += 1)
113-
cout &lt;&lt; &quot;Col &quot; &lt;&lt; c &lt;&lt; &quot; &quot;;
114-
cout &lt;&lt; endl;
115-
116-
for (unsigned r = 0; r &lt; R; r += 1) {
117-
cout &lt;&lt; &quot;Row &quot; &lt;&lt; r &lt;&lt; &quot; &quot;;
118-
for (unsigned c = 0; c &lt; C; c += 1)
119-
cout &lt;&lt; at(r, c) &lt;&lt; &quot; &quot;;
120-
cout &lt;&lt; endl;
121-
}
122-
cout &lt;&lt; endl;
123-
}
124-
125-
Matrix&lt;ValueT, R, C, !ColumnMajor&gt; transposeStorage () const
126-
{
127-
Matrix&lt;ValueT, R, C, !ColumnMajor&gt; result;
128-
129-
for (unsigned r = 0; r &lt; R; r += 1)
130-
for (unsigned c = 0; c &lt; C; c += 1)
131-
result.at(r, c) = at(r, c);
132-
133-
return result;
134-
}
135-
136-
Matrix&lt;ValueT, C, R, !ColumnMajor&gt; transposeMatrix () const
137-
{
138-
Matrix&lt;ValueT, C, R, !ColumnMajor&gt; result;
139-
140-
memcpy(&amp;result.at(0,0), m_values, sizeof(m_values));
141-
142-
return result;
143-
}
144-
};
145-
14661
int main (int argc, char * const argv[]) {
14762
Matrix&lt;float, 4, 2, false&gt; rowMajorMatrix;
14863
Matrix&lt;float, 4, 2, true&gt; columnMajorMatrix;

0 commit comments

Comments
 (0)