Every time you send useless email…
Thursday, November 20th, 2008 1:02am by Ryan Lewis
Thursday, November 20th, 2008 1:02am by Ryan Lewis
Wednesday, November 05th, 2008 2:43am by Ryan Lewis
I just recently purchased a Samsung LN32A450 television and wanted to use it as a monitor. I figured that it shouldn’t be too hard, just plug in my computer to it’s VGA port and then change the resolution.
But, when are new things ever easy?
To make a long story short, I had to generate a custom modeline for X to be able to use the TV’s native resolution, 1360×768. I read to use the command cvt 1360 768 60.015Hz, but the returned modeline resulted in a “Mode Not Supported” error from the TV. Instead, I had to use a Windows program called PowerStrip to grab the custom timings that actually worked. Though, the only reason they worked was by luck because Windows didn’t properly detect the monitor either, so I used PowerStrip to add a custom resolution to my registry which was preset with working timings.
Anyway, PowerStrip was nice enough to generate an xorg.conf modeline for me and had to edit the following in my file (this is assuming that you already have the proprietary nVidia drivers already working):
…
Section "Monitor"
…
Modeline "1360x768" 85.500 1360 1440 1552 1792 768 771 777 795 +hsync +vsync
EndSection
…
Section "Screen"
…
SubSection "Display"
Depth 24
Virtual 1360 768
Modes "1360x768"
EndSubSection
EndSection
…
Note: any ellipses (…) in the above are just cutting out parts that were not changed in my file.
UPDATE: I figured that I would make a note that I recently tried getting a new computer to work with this television and didn’t have as much luck. The new computer was using an ATI Radeon 4850 rather than the nVidia card that I got working previously. Ultimately, I couldn’t get the VGA out to work and had to switch to using an HDMI connection. After I did that, Ubuntu 8.10 (the same OS that I was using previously) automatically detected the native resolution of this TV. Therefore, I recommend using HDMI over VGA to get this TV to work in Linux.
Monday, August 11th, 2008 2:20pm by Ryan Lewis
I mentioned CouchDB in my last post, but didn’t really elaborate on what it was.
Apache CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. Among other features, it provides robust, incremental replication with bi-directional conflict detection and resolution, and is queryable and indexable using a table-oriented view engine with JavaScript acting as the default view definition language.
I’m gonna show you some really basic ways to use CouchDB using a PHP class found on their website and assume that you have PHP 5.1 or greater and CouchDB 0.8 installed successfully.
The first thing that we need to do is create a sample database for us to play eventually play with using PHP. To manage your databases and documents, you can use Futon, CouchDB’s administrative frontend. It can be accessed at http://localhost:5984/_utils. Create a database called “people” with two documents in it with random IDs that each have two fields in them: “name” and “age”. Also, be sure to enter in some values for those.
Let’s look at this PHP file:
<?php
include_once "CouchDB.php";
$couchdb = new CouchDB("people", "localhost");
$view = '{ "map": "function(doc) { emit(null, doc); }" }';
try {
$all = $couchdb->send("/_temp_view", "post", $view)->getBody(true);
}
catch (CouchDBException $e) {
die("[ERROR]".$e->getMessage()."\n");
}
foreach ($all->rows as $k => $row) {
echo "Name: ".$row->value->name." / Age: ".$row->value->age."<br/>";
}
?>
This code is using a temporary view to query the database and then simply looping through the returned JSON and printing data from it. If you set up your database as I mentioned above, $all should be structured like this:
stdClass Object
(
[total_rows] => 2
[offset] => 0
[rows] => Array
(
[0] => stdClass Object
(
[id] => 4144833052c61ab553875737b88ef91a
[key] =>
[value] => stdClass Object
(
[_id] => 4144833052c61ab553875737b88ef91a
[_rev] => 3595404992
[name] => Ryan
[age] => 20
)
)
[1] => stdClass Object
(
[id] => ff3f20d54772b92aad43c36d6ed4abd1
[key] =>
[value] => stdClass Object
(
[_id] => ff3f20d54772b92aad43c36d6ed4abd1
[_rev] => 994830077
[name] => Bob
[age] => 40
)
)
)
)
When I visit the page running the script, it will therefore output this:
Name: Ryan / Age: 20 Name: Bob / Age: 40
If anyone wants to see how to do something, just post a comment and I’ll try to whip something up. Also, the CouchDB Wiki has a lot more information if you’re interested.
Tuesday, August 05th, 2008 2:25pm by Ryan Lewis
I have been working on a web project at work for the past month and used it as an opportunity to learn jQuery and CouchDB.
jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages.
While learning it, I found that there wasn’t a simple tutorial on how to make an ajax form, so here is one:
First, download jQuery from their website and rename the file to “jquery.js” (minus quotes).
Let’s create a file called form.html in the same folder as jquery.js:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Contact Form</title>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#contact").submit(function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "process_form.php",
data: $(this).serialize(),
success: function(html) {
$("#info").html(html);
},
error: function() {
alert("[ERROR] submit");
}
});
});
});
</script>
</head>
<body>
<form id="contact" action="process_form.php" method="POST">
Name <input type="text" name="name" /><br /><br />
Email <input type="text" name="email" /><br />
Message <textarea name="msg"></textarea><br /><br />
<input type="submit" name="submit" value="submit" />
</form>
<p id="info"></p>
</body>
</html>
Next, lets have a file called process_form.php, again in the same folder:
<?php echo "Name: ".$_POST['name']."<br />"; echo "Email: ".$_POST['email']."<br />"; echo "Message: ".$_POST['msg']; ?>
If you load up your pages via a working installation of a webserver with PHP installed, it should return what you entered into the form upon clicking submit. Now that it works, how about an explanation?
This is selecting the element with the id contact and binding to it’s submit event the proceeding function which is being passed event.data by jQuery
$("#contact").submit(function(event) {
Because event was passed to the function, we are now preventing the normal submit actions from being performed. So now when you click the submit button, the page wont refresh and the browser wont call the action script specified in the form tag.
event.preventDefault();
This is how jQuery loads a page using HTTP request. We specify that we want it use POST and the url to request.
$.ajax({
type: "POST",
url: "process_form.php",
This is how we can send the data collected from the form to file being requested. $(this) is referring to the element with an id of contact and serialize is going to do just that: serialize the collected data into a string that can be sent in the request.
data: $(this).serialize(),
This is the function to be called if the request succeeds. In our case, we are going to have it print all returned html into the element with id of info.
success: function(html) {
$("#info").html(html);
},
This is called if the request fails for some reason. In our case, an alert will pop up.
error: function() {
alert("[ERROR] submit");
}
});
});
That concludes this tutorial, if you want to read more about jQuery, there are tons of docs on their official website.