tag:blogger.com,1999:blog-76806815934766475172024-03-06T16:54:55.287+10:00The good kind of madnessRobert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-7680681593476647517.post-18945509382625233192011-05-23T21:26:00.003+10:002011-05-23T21:28:51.633+10:00Rails 3 - Testing Authentication (format html and xml)Hey guys,<br />
<br />
This is a brief post showing you some functional test examples that test site authentication. I'm testing both format:html (via sessions), and format:xml (via HTTP Basic Auth). <br />
<br />
<br />
<b>Format HTML tests</b> (session authorization):<br />
<br />
<pre>test "should show user's account when logged in" do
get :account, { :id => @user.to_param }, { :user => @user.to_param }
assert_response :success
end
</pre><br />
<pre>test "shouldn't show user's account when not logged in" do
get :account, { :id => @user.to_param }
assert_redirected_to new_session_path
end
</pre><br />
<pre>test "shouldn't get edit as logged in as different user" do
get :edit, { :id => @other_user.to_param }, { :user => @user.to_param }
assert_redirected_to user_path(@other_user)
end
</pre><br />
<br />
<b>Format XML Tests</b> (http_auth authorization):<br />
<br />
<pre>test "shouldn't show account (xml) without http_auth provided" do
get :account, { :format => 'xml', :id => @user.to_param }, { :user => @user.to_param }
assert_response :unauthorized
end
</pre><br />
<pre>test "should show account (xml) with http_auth provided" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(@user.user_name, password_for(@user))
get :account, { :format => 'xml', :id => @user.to_param }
assert_response :success
end
</pre><br />
<pre>test "shouldn't show account (xml) with bad http_auth provided" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials('foo', 'bar')
get :account, { :format => 'xml', :id => @user.to_param }
assert_response :unauthorized
end
</pre><br />
<b><i>N.B.</i></b><br />
Assumes that in your test helper files you have a <code>password_for(user)</code> method.<br />
<br />
Assumes the following test setup:<br />
<pre>setup do
@user = users(:joe)
@other_user = users(:jane)
end
</pre>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com0tag:blogger.com,1999:blog-7680681593476647517.post-7376603662277566622010-03-06T16:48:00.006+10:002011-05-22T13:23:42.096+10:00vimrc generatorHey guys and gals,<br />
<br />
I recently got sick of trawling through my old emails to find a .vimrc file a <a href="http://simonbaird.com/">work colleague</a> had previously sent me, so I decided to write a simple .vimrc generator based on the vimrc file I was working with.<br />
<br />
The vimrc generator can be found at <a href="http://vimrcgenerator.appspot.com/">http://vimrcgenerator.appspot.com</a><br />
<br />
I wrote the vimrc generator for appengine. I will probably add the source code to github in the near future.<br />
Enjoy,Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com1tag:blogger.com,1999:blog-7680681593476647517.post-12832833509555916592010-01-24T19:55:00.020+10:002010-01-24T20:30:34.651+10:00Simple fix for the looping "Dropbox daemon not installed!" problem<p>I performed an Ubuntu update the other day, and my dropbox stopped working.<br /></p><p>It kept asking me to install the dropbox daemon, even though I had already installed it.<br /></p><p>I fixed this problem by removing the hidden dropbox folders in my home directory, and then reinstalling the dropbox package.</p><p><br /></p><p><span style="font-weight: bold;">Short answer:</span><br /><br />Remove the two hidden dropbox folders (<code>~/.dropbox</code> and <code>~/.dropbox-dist</code>) from your home directory, and try running dropbox again.</p><p><br /></p><p><span style="font-weight: bold;">Long answer:</span><br /><br />Step 1 - Remove the two hidden dropbox folders:<br /></p><ul><li><code>rm -rfd ~/.dropbox-dist/</code></li><li><code>rm -rfd ~/.dropbox/</code></li></ul><p></p><p>Step 2 - Reinstall dropbox:<br /></p><ul><li><a href="https://www.dropbox.com/downloading">Download the appropriate dropbox</a> for your distro.</li><li>Use the download to reinstall the dropbox package.</li></ul><p></p><p>Step 3 - Open dropbox:<br /></p><ul><li>Open dropbox, dropbox is usually found in your applications drop-down under internet. </li></ul><p></p><p>Step 4 - Install daemon and configure:<br /></p><ul><li>When you run dropbox, it will install the dropbox daemon. Once it has completed that step, it should ask you to log out and in again. Log out, then log back in.<br /></li><li>Once you have logged back in, re-run dropbox. This time when you run dropbox, it will ask you for your login details. Provide your login details.<br /></li><li>Dropbox will now ask where you want to sync your dropbox to. Select the same folder as you previously used.</li></ul><p></p><p>Step 5 - Finished<br /></p><ul><li>Dropbox should now be working again!<br /></li></ul><br /><p></p>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com4tag:blogger.com,1999:blog-7680681593476647517.post-30506023441055207972009-03-04T16:33:00.007+10:002009-05-23T10:54:52.173+10:00Android application release statsHey guys and gals,<br /><br />I have a treat for those of you who are curious about what the uptake rate is for Android apps. I will be sharing my uptake stats via a <a href="http://spreadsheets.google.com/pub?key=pXBzGVD9WcRx_slRPLmvBAA&output=html">google spreadsheet</a>.<br /><br />N.B. These are of course the stats for my apps, meaning that they will not reflect all apps. Also, so far, my apps are for "niche" markets. The release stats would likely be very different for an app such as "Lord of the farts"; Lol, "Lord of the farts".Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com1tag:blogger.com,1999:blog-7680681593476647517.post-90458013346498338092009-02-28T23:43:00.006+10:002010-01-24T16:20:46.410+10:00The most useful piece of code I have written for Android so farThe following code generates a new tab whenever there is an error and prints the error inside the tab. AWESOME. It is quick and easy, and provides you with immediate feedback when something goes wrong.<br /><pre><br />} catch (Exception e) {<br /> tabHost.addTab(tabHost.newTabSpec("ERROR")<br /> .setIndicator("ERROR")<br /> .setContent(R.id.errorText)<br /> );<br /> TextView errorText = (TextView) findViewById(R.id.errorText);<br /> StringBuilder error = new StringBuilder();<br /> error.append("Error: " + e.getMessage() + "\n");<br /> for(StackTraceElement te : e.getStackTrace()) {<br /> error.append("f: " + te.getFileName() + ", m: " + te.getMethodName() + ", l: " + te.getLineNumber() + "\n");<br /> }<br /> errorText.setText(error.toString());<br />}<br /></pre><br /><br />N.B. I am using a TabActivity, the <code>tabHost</code> variable is the result of <code>this.getTabHost()</code>. <br /><code>R.id.errorText</code> refers to a TextView I have in my layout xml.Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com0tag:blogger.com,1999:blog-7680681593476647517.post-5362872005177953982009-02-28T13:50:00.003+10:002009-02-28T13:56:10.648+10:00Ohmage taking shapeHey people,<br /><br />the following is another screen shot. It shows how Ohmage is taking shape. <br />Ohmage can now go from text to color, as well as color to text.<br /><br />In the screen you can see the auto-completion functionality in use.<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjefcLTsPAc3QAVe6By-SFHcCCI3nmcOFKc7LtWMl_Pqo0ko4iDtHoidz14LkvPltB4skJepD6q1nQw0zfS7-Lu7_V0URLXF8RFFi5QoQCI0B74iqblT-6iLV0MaoRzuKMucyqDKGZQVhw/s1600-h/Screenshot-Android+Emulator+(5554)-1.png"><img style="cursor:pointer; cursor:hand;width: 400px; height: 334px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjefcLTsPAc3QAVe6By-SFHcCCI3nmcOFKc7LtWMl_Pqo0ko4iDtHoidz14LkvPltB4skJepD6q1nQw0zfS7-Lu7_V0URLXF8RFFi5QoQCI0B74iqblT-6iLV0MaoRzuKMucyqDKGZQVhw/s400/Screenshot-Android+Emulator+(5554)-1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5307691994438427650" /></a>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com0tag:blogger.com,1999:blog-7680681593476647517.post-8733657711840261122009-02-27T19:32:00.009+10:002009-02-27T20:20:36.303+10:00OhmageHey guys and gals,<br /><br />I've been spending a little bit of time working with <a href="http://en.wikipedia.org/wiki/Google_Android">Android</a> lately. The following is a sneak peek at an app I'm working on. I hope to have it added to the Android market place by the end of this weekend (free app). The app's name is Ohmage, however for stuff and giggles, I may change the name to Pure Ohmage. I should mention that I hope to also have several other features added before I release Ohmage. <br /><br />These features include:<br />1. A "generate colors" based on resistance value (ohms).<br />2. A lookup formula/equation list. This list will <strong>initially</strong> be static.<br />3. A multi tab view to separate the ohmage view from the formula/equation list view.<br /><br />N.B. You may notice the resistor image is very coder-art-ish. The image will be updated before I release Ohmage.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH9agOkMS2bUpHDFgF6ka6onoCG4IkcuJwM0eqY8hJDDRYLQiDqCce16l1fpN_bOLEOuWFIlsQ3-0m32WMJVgCFl4CPlsPgHgTHt7BtwLXoq_VbH6JdM1vvSBX9RSsxhqugmNP7REze8M/s1600-h/Upright.png"><img style="float:bottom; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 238px; height: 400px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH9agOkMS2bUpHDFgF6ka6onoCG4IkcuJwM0eqY8hJDDRYLQiDqCce16l1fpN_bOLEOuWFIlsQ3-0m32WMJVgCFl4CPlsPgHgTHt7BtwLXoq_VbH6JdM1vvSBX9RSsxhqugmNP7REze8M/s400/Upright.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5307409621323050418" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrggBBUq2sclm1n0cqpl4AWkcivGrsZnlTfraJHEcVH4OV1RGbrRHubAUkyZHkJhpnuitTg95gyxmdyY-_NLeFTyl7pYfutk6gLh0p0f-LwaN9KkPdjB7CgjDbHUY4lcIhHUsf49Eemas/s1600-h/SideOn.png"><img style="float:bottom; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 400px; height: 199px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrggBBUq2sclm1n0cqpl4AWkcivGrsZnlTfraJHEcVH4OV1RGbrRHubAUkyZHkJhpnuitTg95gyxmdyY-_NLeFTyl7pYfutk6gLh0p0f-LwaN9KkPdjB7CgjDbHUY4lcIhHUsf49Eemas/s400/SideOn.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5307409621188331570" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwGtT0Uicbp-fC1urW7cdX8cpiu2NB1fHyhrwUcdgsLzLE01QGVD-elVR2y2mqEfmcsaGiaGG47LP8-wMe-nHdkQ7WWYHKks7IpCAYSR_ut1Gu5X_39zm5X19tK6NprkoKhTnL9Q723W8/s1600-h/Selecting+a+color.png"><img style="float:bottom; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 400px; height: 334px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwGtT0Uicbp-fC1urW7cdX8cpiu2NB1fHyhrwUcdgsLzLE01QGVD-elVR2y2mqEfmcsaGiaGG47LP8-wMe-nHdkQ7WWYHKks7IpCAYSR_ut1Gu5X_39zm5X19tK6NprkoKhTnL9Q723W8/s400/Selecting+a+color.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5307409619258296306" /></a><br /><br /><br />Update:<br /><br />While I do only support 4 band resistors, it will be fairly simple to add support for 5 and 6 band resistors. <br /><br />For anyone wanting to know what the learning curve for Android is like, the following is my take on learning Android. I have been working with Android for about 10 hours now. Android programming with the Eclipse plugin is... pleasant :D. Android programs are written in Java and the event system is fairly similar to Java Swing. A lot of the heavy lifting is performed by the Android View, Activity and Adapter classes. <br />The Api Demos included with the SDK are the holy grail for learning Android. They provide excellent examples and clearly show how to perform your layout in xml, rather than in the raw code.<br />If you are considering learning Android, I highly recommend making use of the eclipse plugin and the Api Demos.Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com1tag:blogger.com,1999:blog-7680681593476647517.post-32318755006770552782009-02-07T11:51:00.008+10:002009-02-07T12:27:43.615+10:00Working with SVN (Subversion) on a local network. Use hostnames when checking out.Hello everybody,<br /><br />Firstly, I am working on a new project, "Tiddly Speck" (Working Title), and will return to posting about "Using Ruby to easily scrape/search/spider a web page for "things"" once I have finished the "Tiddly Speck" project.<br /><br />Now on with the post..<br /><br />When working with subversion on a local network, I highly recommend using <a href="http://en.wikipedia.org/wiki/Hostname">hostnames</a> when performing checkouts.<br />You can add custom hostnames by configuring your system's <a href="http://en.wikipedia.org/wiki/Hosts_file">hosts file</a>.<br />If at any point the machine which you were using to checkout from changes its IP address, having used hostnames means you need only reconfigure the entry for the hostname in your hosts file.<br />If you didn't use hostnames you would either need to reconfigure your network to give the machine the original IP address it had, reconfigure all the .svn entries for the checkout, or re-checkout with the new IP address and merge all your old changes into your new checkout.<br /><br /><strong>Example</strong>:<br />I use my mac mini as my subversion "server" at home.<br /><br />My hosts file includes:<br /><pre>127.0.0.1 localhost<br />127.0.1.1 robert-ubuntu-desktop<br />192.168.0.9 macmini</pre><br /><br />This means that I can checkout my repository using a command similar to the following:<br /><code>svn co http://macmini/svn/ my_new_work_area</code><br /><br />If at any time my macmini changes its IP address, I only need to edit the macmini entry in my hosts file with the new IP address.Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com0tag:blogger.com,1999:blog-7680681593476647517.post-3812427284857905142009-02-05T00:06:00.009+10:002009-02-05T21:30:18.439+10:00Ruby - Regex Non-Greedy Operator (?)- Using Ruby to easily scrape/search/spider a web page for "things" - Part 2Hello again,<br /><br />This is part 2 of the "<span style="font-style:italic;">Using Ruby to easily scrape/search/spider a web page for "things"</span>" multi-part post.<br /><br />In this post I will explain the use of the non-greedy regex operator. In the spider example used in part 1, I scraped for all uses of the html heading element. The html heading element includes h1, h2, h3, etc. More specifically, I was looking for all matches of the regex: <code><h[0-9]>(.*?)</h[0-9]></code><br /><br />The following breaks down and explains the above regex:<br /><code><h[0-9]></code> → Find <code><h</code> followed by <code>one digit ([0-9])</code> followed by <code>></code><br /><code>.*?</code> → Find <code>any character (.)</code> <code>zero or more times (*)</code> <code> non-greedily (?)</code><br /><code></h[0-9]></code> → Find <code></h</code> followed by <code>one digit ([0-9])</code> followed by <code>></code><br /><br />The parentheses (), mark what I want to capture from my regex match. In this case, it is the actual heading, I don't want to capture the <code><h[0-9]></code> or the <code></h[0-9]></code>.<br /><br />The non-greedy operator <code>(?)</code> means that the regex should not be greedy; it should look-ahead to see if it can break what it is currently looking at. In the above example, the non-greedy operator was used to prevent the <code>.*</code> from matching everything and thus never allowing the regex to match <code></h[0-9]></code>. The following examples demonstrate greedy vs non-greedy:<br /><br />Example 1: Greedy:<br />Regex: <code><h[0-9]>.*</h[0-9]></code><br />Input: <code><h3>My Title</h3></code><br /><code><h[0-9]></code> matches: <code><h3></code><br /><code>.*</code> matches: <code>My Title</h3></code><br /><br />Example 2: Non-Greedy:<br />Regex: <code><h[0-9]>.*?</h[0-9]></code><br />Input: <code><h3>My Title</h3></code><br /><code><h[0-9]></code> matches: <code><h3></code><br /><code>.*?</code> matches: <code>My Title</code><br /><code></h[0-9]></code> matches: <code></h3></code><br /><br /><strong>Further Reading:</strong><br /><a href="http://doc.infosnel.nl/ruby_regular_expressions.html">Ruby regex, quick reference guide</a><br /><a href="http://www.ruby-doc.org/docs/UsersGuide/rg/regexp.html">Ruby-doc, user's guide to regex</a><br /><a href="http://www.ruby-doc.org/core/classes/Regexp.html">Ruby API: Regexp</a><br /><a href="http://www.rubular.com/">Rubular: A Ruby regular expression editor (Interactive)</a>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com4tag:blogger.com,1999:blog-7680681593476647517.post-53672846113643366392009-02-04T23:49:00.016+10:002009-02-05T09:30:12.295+10:00Ruby - Using Ruby to easily scrape/search/spider a web page for "things" - Part 1Hello,<br /><br />This is part 1 of the "<span style="font-style:italic;">Using Ruby to easily scrape/search/spider a web page for "things"</span>" multi-part post.<br /><br />This part contains the code necessary to scrape a web site for a specific thing. In the case of this example, a heading.<br /><br />The other parts of this multi-part post will explain specific sections of the code and will demonstrate how to spider through a website by scraping for links. <br /><br />The following code can be used to scrape/search/spider a web site for headings:<br /><pre><br />#!/sw/bin/ruby<br />require 'open-uri'<br />require 'pp'<br /><br />spider_url = "http://robertpyke.com/"<br />pp "Looking up #{spider_url}"<br /><br /># The parentheses mark what we want to capture<br />heading_pattern = /<h[0-9]>(.*?)<\/h[0-9]>/ <br /><br />headings = []<br />open(spider_url) do |f|<br /> f.each do |line|<br /> matchdata = line.scan(heading_pattern)<br /> matchdata.each do |match| # Each match, match is an array<br /> match.each do |string| # Each string within a match<br /> headings << string # Store the heading we found<br /> end<br /> end<br /> end<br />end<br />pp headings # Print the headings we found<br /></pre><br /><br /><strong>Note</strong>: It should be noted that the regex used to capture the heading is by no means perfect. It has been provided as a simple starting point for people wanting to scrape web pages. Both the limitations of this regex, and a more advanced regex example, will be provided in a later part of this multi-part blog post.Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com4tag:blogger.com,1999:blog-7680681593476647517.post-15330380019822395292009-02-04T22:22:00.023+10:002009-02-05T21:16:11.649+10:00Ruby - Declaring Strings using %{}Hi guys/gals,<br /><br />In Ruby, you can declare a string like follows:<br /><code>string = "a string"</code><br /><br />You can also declare a string with:<br /><code>string = %{Another string}</code><br /><br />The cool thing about the %{} declaration is that it is context aware. That is to say, it knows the depth of the <a href="http://en.wikipedia.org/wiki/Curly_bracket_programming_language">curly</a> stack. It knows when the next curly will end a start curly within the string and when the next curly will end the curly which started the string.<br /><br />The following example demonstrates this:<br /><code>my_string = <br />%{1st line, it is fairly normal.<br />2nd line , it contains "quotation marks".<br />3rd line, it contains one set of curlies, { a set }.<br />4th, it contains two sets of curlies, { first set }, { second set }.<br />5th line, this marks the end of my_string.}</code><br /><br />The above works because the sets of curlies start and end within the string.<br /><br /><br />The following examples show what will happen if you <strong>incorrectly</strong> use %{}:<br /><br />Input: <code>string = %{hello}world}</code><br />Output: <code>-:1: syntax error, unexpected tIDENTIFIER, expecting $end</code><br /><br />Input: <code>string = %{hello{world}</code><br />Output: <code>-:1: unterminated string meets end of file</code><br /><br /><br /><strong>Update</strong>: As mentioned by <a href="http://www.blogger.com/profile/07800779073409671908">Simon</a>, you can use any non letter/number character to mark the start and end of a string. The character after the <code>%</code> marks the start of the String, if the character has an end pair character, the way in which you declare the String will work as I have described for %{}. If the character does not have an end pair character, the next use of the character will mark the end of the String.<br /><br />Pair characters include: <code>%{}, %[], %(), %<></code><br /><br />The following shows different examples of character combinations you <strong>can</strong> use to start and end a string:<br />Start: <code>%{</code> end: <code>}</code><br />Start: <code>%}</code> end: <code>}</code><br />Start: <code>%[</code> end: <code>]</code><br />Start: <code>%]</code> end: <code>]</code><br />Start: <code>%!</code> end: <code>!</code><br /><br />The following shows an example of a character combination you <strong>cannot</strong> use:<br />Start: <code>%{</code> end: <code>{</code><br /><br />The following are examples of <strong>correct</strong> String declarations: <br /><code>my_string1 = <br />%[My string, I have some other brackets in my String [a, b, c], yay<br />for context aware Strings.]</code><br /><code>my_string2 = %$MyString which is ended by a dollar sign$</code><br /><code>my_string3 = %<Yet another example of a String which is closed by it's sensible pair character></code><br /><code>my_string4 = %%Yes, even the percent sign can be used%</code><br /><br />The following are examples of <strong>invalid/incorrect</strong> String declarations: <br />Input: <code>my_string4 = %1String Content1</code><br />Output: <code>-:1: unknown type of %string</code><br /><br />Input: <code>my_string5 = %aString Contenta</code><br />Output: <code>-:1: unknown type of %string</code><br /><br />Input: <code>my_string6 = %[String Content[</code><br />Output: <code>-:1: unterminated string meets end of file</code>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com3tag:blogger.com,1999:blog-7680681593476647517.post-47236556102061915022009-01-31T16:33:00.006+10:002009-02-05T00:14:11.454+10:00Ruby: Adding the comparison operator (<=>) to the Symbol classHi guys/gals, <br /><br />I'm working on some Ruby at the moment.<br />The code I'm writing uses hash maps and arrays to store word associations. To lower my memory usage, I decided to use symbols. Using symbols means all uses of the same word only use the one symbol worth of memory, instead of using a string worth of memory per word.<br /><br />For example, 800 strings of "a", is a lot more usage than 800 symbols of :a, as the symbol is shared. If I used strings, I would have 800 independent copies of "a".<br /><br />For display purposes, I wanted to sort my arrays of symbols. I soon learned that I could not call .sort! on an array of symbols. This is because the base class "Symbol" does not have <=> (comparison) operator by default. To be able to sort my arrays of symbols, I needed to add a <=> method to Symbol. The following code shows how to do this: <br /><br /><pre>class Symbol<br /> def <=> value<br /> to_s <=> value.to_s<br /> end<br />end</pre><br /><br />The code above injects a <=> (comparison) method into the Symbol class. The <=> method simply converts the symbols that it is comparing to strings, and then calls the string <=> method. <br /><br />Note: I wrote the <=> method for my own purpose, to sort my symbols alphabetically. You could have just as easily written a method which compares symbols based on their length.<br /><br /><a href="http://www.ruby-doc.org/core/classes/Symbol.html">Ruby API: Symbol</a><br /><a href="http://www.ruby-doc.org/core/classes/String.html#M000778">Ruby API: String#Comparison</a>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com3tag:blogger.com,1999:blog-7680681593476647517.post-14877008252869080332009-01-26T22:34:00.004+10:002009-01-26T23:06:58.064+10:00ruby-tower-defenceHey guys/gals,<br /><br />I have just spent the past long weekend on a coding binge, 20+ hours of lovely Ruby. The end result is a tower defence "game" with easy to use base classes, making it easy for anyone to add a level, a tower or even a new bullet type. The "game" is in a playable state, and anyone who his familiar with rubygame should check it out. The "game" is available via <a href="http://github.com/brimstone4814/ruby-tower-defence/tree/master">GIT</a>.<br /><br />The following is a screenshot of ruby-tower-defence in action:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIFazz-fFVkxsT8g_ojICzPVoy7zuspzESnJghn2In82Cm1k8Q859ayjm0EGU2Q1qCEGHLcsEswgr0lEPypx6c8rPL7eTl4ohUWImzg0Rg0e3aWfdsIRKvO86m3_JBRtGN28SMEd0i0W8/s1600-h/ruby-tower-defence"><img style="margin: 0pt 0pt 10px 10px; width: 400px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIFazz-fFVkxsT8g_ojICzPVoy7zuspzESnJghn2In82Cm1k8Q859ayjm0EGU2Q1qCEGHLcsEswgr0lEPypx6c8rPL7eTl4ohUWImzg0Rg0e3aWfdsIRKvO86m3_JBRtGN28SMEd0i0W8/s400/ruby-tower-defence" alt="" id="BLOGGER_PHOTO_ID_5295586053572476354" border="0" /></a>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com0tag:blogger.com,1999:blog-7680681593476647517.post-47986931265425029002008-11-13T12:55:00.003+10:002009-01-26T23:07:45.650+10:00Ruby Pong - Screenshot<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaYCIklElp0L5dWHHwfTpW0jMUDF_0dah_h4GZW0hXtiriBo2UUhqMD79DBxd1PMyr5LycQshyl0IwjlukOSAFOMKCC6Hidq1j_KC5AElvRzV8BJf62hXlVGPOkIB_g0Ss_0GDmzZFhiU/s1600-h/Screenshot-FPS:+29.107946580093.png"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 400px; height: 212px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaYCIklElp0L5dWHHwfTpW0jMUDF_0dah_h4GZW0hXtiriBo2UUhqMD79DBxd1PMyr5LycQshyl0IwjlukOSAFOMKCC6Hidq1j_KC5AElvRzV8BJf62hXlVGPOkIB_g0Ss_0GDmzZFhiU/s400/Screenshot-FPS:+29.107946580093.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5267970677640391346" /></a><br /><br />The above is a screenshot of the game, Pong, which I discussed in my last post.Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com0tag:blogger.com,1999:blog-7680681593476647517.post-58219491749431889942008-11-02T23:03:00.004+10:002008-11-02T23:44:11.654+10:00Pong (the game)- RubygameI have just finished writing Pong, my first full featured game, in <span style="font-weight: bold;">Rubygame</span>.<br />On top of just the normal Pong action, I have added sound effects and background music.<br /><br />I have uploaded my source code to my website. Consider the source code "free", i.e. do what you like with it.<br />You can <a href="http://robertpyke.com/resources/Pong/">browse the source code online</a>.<br /><br /><span style="font-weight: bold;">Giving credit where credit is due</span>:<br />The main tutorial I used to learn how to create Pong was from the <a href="http://kibabase.libregamewiki.org/index.php/The_Rubygame_Book">"Rubygame Book".</a> It is an excellent starting tutorial. It explains a lot of the initial framework setup.<br /><br />The background music is from the <a href="http://github.com/jacius/rubygame/tree/master/samples/">Rubygame samples</a>. These can be found with the latest release of Rubygame.<br /><br />The sound effects are from <a href="http://freesoundfiles.tintagel.net/Audio/">http://freesoundfiles.tintagel.net/Audio/</a><br /><br /><span style="font-weight: bold;">Questions?<span style="font-weight: bold;"><span style="font-weight: bold;"></span></span></span><br />Feel free to ask any questions you may have regarding the source code, or other ruby related issues you may have.<br /><a href="http://kibabase.libregamewiki.org/index.php/The_Rubygame_Book"></a>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com1tag:blogger.com,1999:blog-7680681593476647517.post-15542955799354550952008-11-01T02:12:00.013+10:002008-11-01T14:20:00.415+10:00Rubygame setupI have just completed my first mock game in rubygame (ruby's version of pygame), and I can't recommend it enough. That said, I did have a few troubles setting it up. The following describes how to setup rubygame in Ubuntu 8.04 (this is likely to work with other recent Ubuntu releases):<br /><br />1. Download the rubygame gem from the <a href="http://rubygame.sourceforge.net/">rubygame official site</a>. The gem is currently version 2.3.0.<br />2. Install any necessary libraries. The README from the rubygame site states that you are required to have:<br /><br />1. ruby >= 1.8<br />2. SDL >= 1.2.7<br />3. rake >= 0.7.0 (for build/install system)<br /><br />and that you should, but don't have to have:<br /><br />1. SDL_gfx >= 2.0.10<br />2. SDL_image >= 1.2.3<br />3. SDL_mixer >= 1.2.7<br />4. SDL_ttf >= 2.0.6<br /><br />I found that I <span style="font-weight: bold;">had</span> to have the last 4 SDL libraries to install the rubygame gem.<br /><br />So, in case you don't already have ruby, rake and gems, the following <a href="http://wiki.rubyonrails.com/rails/pages/RailsOnUbuntu">ruby rails website</a> lists the required commands to install ruby, rake and gems. Note, it will also install rails support, which is a good thing.<br /><br />To get the required SDL libraries for rubygame, I installed the following packages via apt-get<br /><br />1. libsdl-ruby1.8<br />2. libsdl1.2-all<br />3. libsdl1.2-dev<br />4. libsdl-gfx1.2-dev<br />5. libsdl-image1.2-dev<br />6. libsdl-mixer1.2-dev<br />7. libsdl-ttf2.0-dev<br /><br />E.g. sudo apt-get install libsdl-ruby1.8<br /><br />Once that was complete, I installed the gem. To install the gem, you must be in a terminal at the directory in which the gem is located. You cannot be in another directory, if you are, it won't find the gem.<br /><br />To install the gem, I did the following:<br /><br />1. I placed the .gem file I downloaded on my Desktop.<br />2. I did the following in the terminal to take me to my gem: cd ~/Desktop<br />3. I did the following in the terminal to install the gem: gem install gem_file.gem<br /><br />If you did not receive a gem "install failed" message, you are ready to use rubygame. If you did, read the error message, I found that the error message named the libraries I was missing. An example of an error I received was, "could not find file SDL_IMAGE.h". This error meant that I was missing the libsdl-image1.2-dev package.<br /><br />The following is an example ruby program you can use to test your rubygame install. Note this is the entire file contents. If your ruby install worked, the app will run, opening a window titled "Hello World".<br /><br /><pre style=";font-family:courier new;font-size:85%;" ><br />#START FILE<br /><br />require "rubygems"<br />require "rubygame"<br /><br />Rubygame.init<br /><br />screen = Rubygame::Screen.set_mode [320,240]<br />screen.title = 'Hello World'<br />screen.update<br /><br />queue = Rubygame::EventQueue.new<br /><br />game_over = false<br /><br />until game_over do<br /> queue.each do |event|<br /> case event<br /> when Rubygame::ActiveEvent<br /> puts "Hello World. Updating"<br /> screen.update<br /> when Rubygame::QuitEvent<br /> game_over = true<br /> end<br /> end<br />end<br /><br />Rubygame.quit<br /><br /># END FILE<br /></pre>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com2tag:blogger.com,1999:blog-7680681593476647517.post-61322438782991677972008-07-07T22:21:00.007+10:002009-09-23T19:26:05.723+10:00Ubuntu, Mediatomb, VLC and the PS3 - a match made in heaven.<span style=";font-family:arial;font-size:100%;" >Today, in the space of a couple of hours, I successfully setup media serving to my PS3 under Ubuntu 8.04. Not only that, but the media server works with:<br /></span><ul style="font-family:arial;"><li><span style="font-size:100%;">Multiple video and audio codecs and</span></li><li><span style="font-size:100%;">Media </span><span style="font-style: italic;font-size:100%;" >scanning</span><span style="font-size:100%;"> (tracking forwards and backwards).</span></li></ul><span style=";font-family:arial;font-size:100%;" >The following discusses how I accomplished this </span><span style="font-style: italic;font-family:arial;font-size:100%;" >feat</span><span style=";font-family:arial;font-size:100%;" >.<br /><br /></span><span style="font-weight: bold;font-family:arial;font-size:100%;" >Introduction:</span><span style=";font-family:arial;font-size:100%;" ><br /><br />Firstly it should be noted that the PS3 is a DLNA (Digital Living Network Alliance) compatible device, this basically means you can share media to it. Currently under Ubuntu there is a limited number of DLNA compatible media server programs, these programs include </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" > and </span><span style="font-style: italic;font-family:arial;font-size:100%;" >fuppes.</span><span style=";font-family:arial;font-size:100%;" > I chose </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" > as it has an installer through the symantic package manager, and for that reason updates should be automated.<br /><br /><br /></span><span style="font-weight: bold;font-family:arial;font-size:100%;" >Installation:</span><span style=";font-family:arial;font-size:100%;" ><br /><br />First, make sure you have </span><span style="font-style: italic;font-family:arial;font-size:100%;" >VLC</span><span style=";font-family:arial;font-size:100%;" > installed, if you don't you can install it using the following command: <code>sudo apt-get install vlc</code><br /><br />Also install </span><span style="font-style: italic;font-family:arial;font-size:100%;" >ffmpeg</span><span style=";font-family:arial;font-size:100%;" > for good measure: <code>sudo apt-get install ffmpeg</code><br /><br />I performed the installation of </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" > via the </span><span style="font-style: italic;font-family:arial;font-size:100%;" >Add/Remove </span><span style=";font-family:arial;font-size:100%;" >programs (symantic package manager) application in Ubuntu.<br />Simply search for </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" > in the "All available programs" category and select install. Having completed the previous install step, <span style="font-style: italic;">mediatomb</span> is now successfully installed and is avaliable under "Application/Sound & Video", that said, don't open it yet!<br /><br /><br /></span><span style="font-weight: bold;font-family:arial;font-size:100%;" >Configuration:</span><span style=";font-family:arial;font-size:100%;" ><br /><br />Now we need to setup </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" >, to do this we first need to run and close </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" >, this will cause </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" > to do some basic setup. To run </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" >, go to a terminal and type: <code>sudo mediatomb</code><br />After you do this wait for some text to output, the text should look something like:<br /><br /></span><pre style="font-family:arial;"><span style="font-size:100%;"><br />MediaTomb UPnP Server version 0.11.0 - http://mediatomb.cc/<br /><br />===============================================================================<br />Copyright 2005-2008 Gena Batsyan, Sergey Bostandzhyan, Leonhard Wimmer.<br />MediaTomb is free software, covered by the GNU General Public License version 2<br /><br />2008-07-08 22:47:45 INFO: Loading configuration from: /home/user/.mediatomb/config.xml<br />2008-07-08 22:47:45 INFO: Checking configuration...<br />2008-07-08 22:47:45 INFO: Setting filesystem import charset to UTF-8<br />2008-07-08 22:47:45 INFO: Setting metadata import charset to UTF-8<br />2008-07-08 22:47:45 INFO: Setting playlist charset to UTF-8<br />2008-07-08 22:47:45 INFO: Configuration check succeeded.<br />2008-07-08 22:47:45 INFO: Initialized port: 49152<br /></span></pre><span style=";font-family:arial;font-size:100%;" ><br /><br />Once the text is outputted close the program, <code>CTRL+C</code>.<br /><br />Now edit the </span><span style="font-style: italic;font-family:arial;font-size:100%;" >mediatomb</span><span style=";font-family:arial;font-size:100%;" > configuration file, to do this simply edit the config.xml file for mediatomb using your text editor: <code>gedit ~/.mediatomb/config.xml</code><br /><br />Note that the file has some comments which instruct you where to change things for PS3 support.<br /><br />Line 23: Change the no to a yes, <code>protocolInfo extend = yes</code><br />Before:<br /><code><protocolInfo extend="no"/><!-- For PS3 support change to "yes" --></code><br />After:<br /><code><protocolInfo extend="yes"/><!-- For PS3 support change to "yes" --></code><br /><br />Line 65: Uncomment, <code>map from="avi" to="video/divx" </code><br />Before:<br /><code><!-- <map from="avi" to="video/divx"/> --></code><br />After:<br /><code><map from="avi" to="video/divx"/></code><br /><br />The above gives you the basic <span style="font-style: italic;">mediatomb</span> PS3 support, this basic support will not transcode your files. This means that if a media file isn't encoded using one of the "few" supported codecs then <span style="font-style: italic;">tough luck</span>.<br /><br />To enhance the PS3 support enable transcoding, as <span style="font-style: italic;">VLC</span> is installed, enable transcoding via <span style="font-style: italic;">VLC</span>.<br /><br />Line 87: Change the no to a yes, <code>transcoding enabled="yes"</code><br />Before:<br /><code><transcoding enabled="no"></code><br />After:<br /><code><transcoding enabled="yes"></code><br /><br />Line 103: Change the enabled from no to yes, <code>profile name="vlcmpeg" enabled="yes" type="external"</code><br />Before:<br /><code><profile name="vlcmpeg" enabled="no" type="external"></code><br />After:<br /><code><profile name="vlcmpeg" enabled="yes" type="external"><br /><br /></code>Having completed the above steps, save the file.<br /><br />All that remains is to re-run the <span style="font-style: italic;">mediatomb</span> via the terminal and add media to share. Simply run <span style="font-style: italic;">mediatomb</span> in a terminal:<code>mediatomb</code>. Now go to the URL stated in the <span style="font-style: italic;">mediatomb</span> output, this is likely to be <code>http://localhost:49152</code>. Once at the URL you should see the <span style="font-style: italic;">mediatomb</span> interface, to add media simply select the media you want to share from the <span style="font-style: italic;">Filesystem</span> and press the <span style="font-style: italic;">+</span> symbol in the top right. All shared media is shown in the <span style="font-style: italic;">Database</span>.<br /><br /><br /><span style="font-weight: bold;">Finish:<br /><br /></span>Now startup your PS3 and search for media servers, your PS3 should find the <span style="font-style: italic;">mediatomb</span> server with your shared media, virtually all the media should be watchable via the <span style="font-style: italic;">VLC</span> transcoding.. Enjoy!<br /><br /><br /><span style="font-weight: bold;">config.xml</span> <span style="font-style: italic;">before and after</span>:<br /><br /><span style="font-weight: bold;">Before:<br /></span></span> <pre style="font-family:arial;"><span style="font-size:100%;"><pre><?xml version="1.0" encoding="UTF-8"?><br /><config version="1" xmlns="http://mediatomb.cc/config/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/1 http://mediatomb.cc/config/1.xsd"><br /> <server><br /> <ui enabled="yes"><br /> <accounts enabled="no" session-timeout="30"><br /> <account user="mediatomb" password="mediatomb"/><br /> </accounts><br /> </ui><br /> <name>MediaTomb</name><br /> <udn>uuid:77026039-2855-4f76-bb54-4f7b176d4cb8</udn><br /> <home>/home/robertpyke/.mediatomb</home><br /> <webroot>/usr/share/mediatomb/web</webroot><br /> <storage><br /> <sqlite3 enabled="yes"><br /> <database-file>mediatomb.db</database-file><br /> </sqlite3><br /> <mysql enabled="no"><br /> <host>localhost</host><br /> <username>mediatomb</username><br /> <database>mediatomb</database><br /> </mysql><br /> </storage><br /> <protocolInfo extend="no"/><!-- For PS3 support change to "yes" --><br /> <!--<br /> Uncomment the lines below to get rid of jerky avi playback on the<br /> DSM320 or to enable subtitles support on the DSM units<br /> --><br /> <!--<br /> <custom-http-headers><br /> <add header="X-User-Agent: redsonic"/><br /> </custom-http-headers><br /><br /> <manufacturerURL>redsonic.com</manufacturerURL><br /> <modelNumber>105</modelNumber><br /> --><br /> <!-- Uncomment the line below if you have a Telegent TG100 --><br /> <!--<br /> <upnp-string-limit>101</upnp-string-limit><br /> --><br /> </server><br /> <import hidden-files="no"><br /> <scripting script-charset="UTF-8"><br /> <common-script>/usr/share/mediatomb/js/common.js</common-script><br /> <playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script><br /> <virtual-layout type="builtin"><br /> <import-script>/usr/share/mediatomb/js/import.js</import-script><br /> </virtual-layout><br /> </scripting><br /> <mappings><br /> <extension-mimetype ignore-unknown="no"><br /> <map from="mp3" to="audio/mpeg"/><br /> <map from="ogg" to="application/ogg"/><br /> <map from="asf" to="video/x-ms-asf"/><br /> <map from="asx" to="video/x-ms-asf"/><br /> <map from="wma" to="audio/x-ms-wma"/><br /> <map from="wax" to="audio/x-ms-wax"/><br /> <map from="wmv" to="video/x-ms-wmv"/><br /> <map from="wvx" to="video/x-ms-wvx"/><br /> <map from="wm" to="video/x-ms-wm"/><br /> <map from="wmx" to="video/x-ms-wmx"/><br /> <map from="m3u" to="audio/x-mpegurl"/><br /> <map from="pls" to="audio/x-scpls"/><br /> <map from="flv" to="video/x-flv"/><br /> <!-- Uncomment the line below for PS3 divx support --><br /> <!-- <map from="avi" to="video/divx"/> --><br /> <!-- Uncomment the line below for D-Link DSM / ZyXEL DMA-1000 --><br /> <!-- <map from="avi" to="video/avi"/> --><br /> </extension-mimetype><br /> <mimetype-upnpclass><br /> <map from="audio/*" to="object.item.audioItem.musicTrack"/><br /> <map from="video/*" to="object.item.videoItem"/><br /> <map from="image/*" to="object.item.imageItem"/><br /> </mimetype-upnpclass><br /> <mimetype-contenttype><br /> <treat mimetype="audio/mpeg" as="mp3"/><br /> <treat mimetype="application/ogg" as="ogg"/><br /> <treat mimetype="audio/x-flac" as="flac"/><br /> <treat mimetype="image/jpeg" as="jpg"/><br /> <treat mimetype="audio/x-mpegurl" as="playlist"/><br /> <treat mimetype="audio/x-scpls" as="playlist"/><br /> <treat mimetype="audio/x-wav" as="pcm"/><br /> <treat mimetype="audio/L16" as="pcm"/><br /> <treat mimetype="video/x-msvideo" as="avi"/><br /> </mimetype-contenttype><br /> </mappings><br /> </import><br /> <transcoding enabled="no"><br /> <mimetype-profile-mappings><br /> <transcode mimetype="video/x-flv" using="vlcmpeg"/><br /> <transcode mimetype="application/ogg" using="vlcmpeg"/><br /> <transcode mimetype="application/ogg" using="oggflac2raw"/><br /> <transcode mimetype="audio/x-flac" using="oggflac2raw"/><br /> </mimetype-profile-mappings><br /> <profiles><br /> <profile name="oggflac2raw" enabled="no" type="external"><br /> <mimetype>audio/L16</mimetype><br /> <accept-url>no</accept-url><br /> <first-resource>yes</first-resource><br /> <accept-ogg-theora>no</accept-ogg-theora><br /> <agent command="ogg123" arguments="-d raw -f %out %in"/><br /> <buffer size="1048576" chunk-size="131072" fill-size="262144"/><br /> </profile><br /> <profile name="vlcmpeg" enabled="no" type="external"><br /> <mimetype>video/mpeg</mimetype><br /> <accept-url>yes</accept-url><br /> <first-resource>yes</first-resource><br /> <accept-ogg-theora>yes</accept-ogg-theora><br /> <agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit"/><br /> <buffer size="14400000" chunk-size="512000" fill-size="120000"/><br /> </profile><br /> </profiles><br /> </transcoding><br /></config></pre><pre style="font-family:arial;"><span><span style="font-size:100%;"></span></span></pre></span></pre><span style=";font-family:arial;font-size:100%;" ><br /></span><span style="font-weight: bold;font-family:arial;font-size:100%;" >After:</span><span style=";font-family:arial;font-size:100%;" ><br /></span><pre style="font-family:arial;"><span><span style="font-size:100%;"><pre><br /><span style="font-size:100%;"><?xml version="1.0" encoding="UTF-8"?><br /><config version="1" xmlns="http://mediatomb.cc/config/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/1 http://mediatomb.cc/config/1.xsd"><br /> <server><br /> <ui enabled="yes"><br /> <accounts enabled="no" session-timeout="30"><br /> <account user="mediatomb" password="mediatomb"/><br /> </accounts><br /> </ui><br /> <name>MediaTomb</name><br /> <udn>uuid:77026039-2855-4f76-bb54-4f7b176d4cb8</udn><br /> <home>/home/robertpyke/.mediatomb</home><br /> <webroot>/usr/share/mediatomb/web</webroot><br /> <storage><br /> <sqlite3 enabled="yes"><br /> <database-file>mediatomb.db</database-file><br /> </sqlite3><br /> <mysql enabled="no"><br /> <host>localhost</host><br /> <username>mediatomb</username><br /> <database>mediatomb</database><br /> </mysql><br /> </storage><br /> <protocolInfo extend="yes"/><!-- For PS3 support change to "yes" --><br /> <!--<br /> Uncomment the lines below to get rid of jerky avi playback on the<br /> DSM320 or to enable subtitles support on the DSM units<br /> --><br /> <!--<br /> <custom-http-headers><br /> <add header="X-User-Agent: redsonic"/><br /> </custom-http-headers><br /><br /> <manufacturerURL>redsonic.com</manufacturerURL><br /> <modelNumber>105</modelNumber><br /> --><br /> <!-- Uncomment the line below if you have a Telegent TG100 --><br /> <!--<br /> <upnp-string-limit>101</upnp-string-limit><br /> --><br /> </server><br /> <import hidden-files="no"><br /> <scripting script-charset="UTF-8"><br /> <common-script>/usr/share/mediatomb/js/common.js</common-script><br /> <playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script><br /> <virtual-layout type="builtin"><br /> <import-script>/usr/share/mediatomb/js/import.js</import-script><br /> </virtual-layout><br /> </scripting><br /> <mappings><br /> <extension-mimetype ignore-unknown="no"><br /> <map from="mp3" to="audio/mpeg"/><br /> <map from="ogg" to="application/ogg"/><br /> <map from="asf" to="video/x-ms-asf"/><br /> <map from="asx" to="video/x-ms-asf"/><br /> <map from="wma" to="audio/x-ms-wma"/><br /> <map from="wax" to="audio/x-ms-wax"/><br /> <map from="wmv" to="video/x-ms-wmv"/><br /> <map from="wvx" to="video/x-ms-wvx"/><br /> <map from="wm" to="video/x-ms-wm"/><br /> <map from="wmx" to="video/x-ms-wmx"/><br /> <map from="m3u" to="audio/x-mpegurl"/><br /> <map from="pls" to="audio/x-scpls"/><br /> <map from="flv" to="video/x-flv"/><br /> <!-- Uncomment the line below for PS3 divx support --><br /> <map from="avi" to="video/divx"/><br /> <!-- Uncomment the line below for D-Link DSM / ZyXEL DMA-1000 --><br /> <!-- <map from="avi" to="video/avi"/> --><br /> </extension-mimetype><br /> <mimetype-upnpclass><br /> <map from="audio/*" to="object.item.audioItem.musicTrack"/><br /> <map from="video/*" to="object.item.videoItem"/><br /> <map from="image/*" to="object.item.imageItem"/><br /> </mimetype-upnpclass><br /> <mimetype-contenttype><br /> <treat mimetype="audio/mpeg" as="mp3"/><br /> <treat mimetype="application/ogg" as="ogg"/><br /> <treat mimetype="audio/x-flac" as="flac"/><br /> <treat mimetype="image/jpeg" as="jpg"/><br /> <treat mimetype="audio/x-mpegurl" as="playlist"/><br /> <treat mimetype="audio/x-scpls" as="playlist"/><br /> <treat mimetype="audio/x-wav" as="pcm"/><br /> <treat mimetype="audio/L16" as="pcm"/><br /> <treat mimetype="video/x-msvideo" as="avi"/><br /> </mimetype-contenttype><br /> </mappings><br /> </import><br /> <transcoding enabled="yes"><br /> <mimetype-profile-mappings><br /> <transcode mimetype="video/x-flv" using="vlcmpeg"/><br /> <transcode mimetype="application/ogg" using="vlcmpeg"/><br /> <transcode mimetype="application/ogg" using="oggflac2raw"/><br /> <transcode mimetype="audio/x-flac" using="oggflac2raw"/><br /> </mimetype-profile-mappings><br /> <profiles><br /> <profile name="oggflac2raw" enabled="no" type="external"><br /> <mimetype>audio/L16</mimetype><br /> <accept-url>no</accept-url><br /> <first-resource>yes</first-resource><br /> <accept-ogg-theora>no</accept-ogg-theora><br /> <agent command="ogg123" arguments="-d raw -f %out %in"/><br /> <buffer size="1048576" chunk-size="131072" fill-size="262144"/><br /> </profile><br /> <profile name="vlcmpeg" enabled="yes" type="external"><br /> <mimetype>video/mpeg</mimetype><br /> <accept-url>yes</accept-url><br /> <first-resource>yes</first-resource><br /> <accept-ogg-theora>yes</accept-ogg-theora><br /> <agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit"/><br /> <buffer size="14400000" chunk-size="512000" fill-size="120000"/><br /> </profile><br /> </profiles><br /> </transcoding><br /></config><br /></span></pre></span></span></pre><br /><br />The associated <span style="font-style: italic;">before</span> and <span style="font-style: italic;">after</span> <span style="font-weight: bold;">config.xml</span> files are available at <a href="http://robertpyke.com/mediatombTutorial1.html">robertpyke.com</a>Robert Pykehttp://www.blogger.com/profile/03780469777703496199noreply@blogger.com11