I am playing with CouchDB a bit this weekend and I am trying to put together a basic application written in HTML and Javascript.
I wanted to use the XMLHttpRequest object to interact with CouchDB; this meant I had to host the code using the web server that is built into CouchDB (to avoid cross domain issues in the browser). However when I first moved the code over from my normal Apache server into the CouchDB server I tried to access the code with my browser at http://localhost:5984/_utils/myapplication and none of my external CSS or Javascript files would load (at least in Firefox).
What I noticed was that since I was using relative paths in the href and src attributes (i.e. <script scr="./file.js" ...) of the link and script tags, the trailing slash on the URL was required for the files to be included properly. I figured this out because when I accessed the same code at http://localhost:5984/_utils/myapplication/, everything worked as expected.
Typically web servers add that slash automatically for you, but for some reason CouchDB does not. To get around this I wrote a quick Javascript that I placed inline, just below the head tag to look for this case and correct it. The script is below.
if(String(window.location).substring((String(window.location).length - 1), String(window.location).length) != '/') {
window.location = String(window.location) + '/';
}
Seems odd that CouchDB does not account for this.
Been getting into Android a good bit lately. Some for work, some not. Anyway I needed a way to scan a barcode on the phone in order to lookup some information for an application I am designing. However as I found out reading a barcode is not a part of the Android SDK. The SDK does support taking pictures and so forth but no analysis or translation.
After some research I found out how to pull it off on the phone; you can do it by accessing an external barcode scanning application using and SDK concept called Intent. The main barcode scanning application (called "Barcode Scanner" in the market) supports returning scanned codes back to other applications, which makes this relatively straight forward to accomplish. I haven't tried this yet in code but the thing I wonder about is if the Android SDK (or the market) handles application dependences or if that is something you have to handle yourself inside of the application.
Details on getting a scanned code into your application in Android using Intent is detailed in the link below.
http://code.google.com/p/zxing/wiki/ScanningViaIntent
The main project for the Android barcode scanner application is below.
http://code.google.com/p/zxing/
I can't see any reason why this application shouldn't be a default application within the software stack and fully integrated into the SDK. It is a top notch application and open source (not sure if the licenses would be compatible).
I have been working some with the Gadget Spec and developing gadgets for use on closed networks. I have been using Shindig to render my gadgets and it is really big on caching gadgets for performance. This is quite annoying when you are developing and tweaking a particular gadget because your changes don't get shown like they should when you refresh the browser.
Anyway, it turns out there is a simple fix for this. Normally you call a URL similar to this to render you gadget in Shindig.
http://your-shindig-server/gadgets/ifr?url=http://url/to/your/gadget.xml
To get Shindig to bypass its cache and pull the latest gadget code all you have to do is add a bpc=1 to the URL query string.
http://your-shindig-server/gadgets/ifr?bpc=1&url=http://url/to/your/gadget.xml
This makes working on a gadget a lot less painful.
Removing the .svn folders from a codebase effectively removes the codes attachment to the repository. This can be useful for when you are trying to distribute the code to others or if you are trying to bring two different repositories together.
Anyway the proper way to do it is to use svn export. However this requires you to specify an export path and you end up with two copies of the codebase. Also the export method doesn't also export any changes you have made to the codebase that have not been committed. See the following link for more details on svn export.
http://svnbook.red-bean.com/en/1.1/re10.html
The easy way to do this is to use the following command.
find ./ -name ".svn" | xargs rm -rf
This will take the current directory and strip the .svn folder out. Be warned though this will also remove files named .svn, normally this should not be a problem.
I got most of this information from the link below.
http://cephas.net/blog/2007/04/06/command-line-script-to-delete-svn-files-folders/
I have have been developing on a MySQL database where a small amount of test data is still over a half a million rows or more. So exporting the schema to pass it along to others takes forever. Fortunately you can export just the structure of the database and nothing else (which is much faster).
mysqldump -h hostname -u user database -RQdp > structure.sql
The option d is the key here. It stands for "no data". The option R will make it include your stored procedures and functions. And the option Q puts backticks (`) around your table names, column names, etc to prevent keyword errors on import.
Alternatively you can also export just the data.
mysqldump -h hostname -u user database -Qtp > data.sql
The option t means "no create info". Which means it wont put any CREATE TABLE statements in your export.
Here is a Javascript function that I threw together the other day that will take the default format of a MySQL DATETIME or TIMESTAMP field (YYYY-MM-DD HH:MM:SS) and convert it into a Date object in Javascript.
function parse_date(string) {
var date = new Date();
var parts = String(string).split(/[- :]/);
date.setFullYear(parts[0]);
date.setMonth(parts[1] - 1);
date.setDate(parts[2]);
date.setHours(parts[3]);
date.setMinutes(parts[4]);
date.setSeconds(parts[5]);
date.setMilliseconds(0);
return date;
}
I actually don't work with Zope as much as I used to but I was going through some old notes and found this gem to backup a Zope instance's Data.fs file while the server is still running. Between the Data.fs file and the Products and Extensions folders you fundamentally have a full backup of your Zope instance.
/usr/lib/zope2.9/bin/repozo.py -BvzQ -r ./ -f /var/lib/zope2.9/instance/instance_name/var/Data.fs
Depending on where Zope is installed the repozo.py script may be in a different place. The -BvzQ is a basic options set (see the man page for details). The -r is where you are backing up to; in this example it is the current directory. And finally the -f is where the Zope instance's Data.fs is.
This is a php script that I wrote a number of years ago. It allows you to search through schema of MySQL databases by table column name. It can connect to multiple servers and it will search the structure of every table in every database.
It is a great tool to find related columns in a complex server situation. You can get the source code here, feel free to download and use it.
I found this in an old email that I sent to myself. I wrote this utility at my first job out of college. They had a software system that had been through a number of reincarnations over the years and they were left with redundant data across numerous servers and databases. I used this script to locate related fields across systems and would then write translation code that would merge data into a consolidated system.
This is just a couple of good tools to find out if your server is allowing spammers to route mail through it. The nice thing about these tools is that you don't have to know how a mail server works to test.
This first one will search a large number of major blacklists to see if your server is listed. Being blacklisted means that a number of sources have identified your server as a source of spam email. If you find yourself on one of these lists, it could be a good indication that your server is sending out spam.
http://www.mxtoolbox.com/blacklists.aspx
You can find out why you are blacklisted by a particular list by checking out their website (which is linked to in the report). Then you can repeal the listing to get your server taken off of the list. If you are listed you should definitely try to get your server off of the list, because being listed could severely reduce the delivery chances of legitimate email generated by your server.
The second tool analyzes your server by trying to connect to it in the same way a spammer would. If it does find an opening, you can have it actually try to send a message through your server, just like a spammer would (this requires you to register to the site). This is a surefire way to know if your server is capable of being abused for spamming. Because if you get the test message in your inbox, that means spammers can do the same thing.
http://www.abuse.net/relay.html
I have wanted to try out OpenOffice.org Base for some time now, but I have never taken the time to figure out how to make it connect to a relational database system. And as it turns out there doesn't seem to be all that much documentation to help. Anyway I needed to figure out a way to look over the structure of a Microsoft SQL database and I didn't have access to a Windows machine, let alone Enterprise Manager.
So OpenOffice.org uses JDBC to connect to various databases, but sadly it does not come bundled with any of the libraries required to connect and communicate. So after researching a little I came across jTDS. And with a little messing around I got it to work. Below is what I did.
-
First you have to download jTDS at http://sourceforge.net/project/showfiles.php?group_id=33291.
-
Second, uncompress the file and store it somewhere out of the way on your computer (such that you don't accidentally move or delete it). You can store the whole folder or just the jtds-x.x.x.jar file.
-
Third, open up OpenOffice.org and go to Tools, Options..., OpenOffice.org (or NeoOffice), Java and then click on Class Path... and then Add Archive.... Choose the jtds-x.x.x.jar file and hit Open. Then keep hitting Ok until all preference windows are closed.
-
Fourth, you need to close and reopen OpenOffice.org for the change to take effect.
-
Fifth, open up Base and when the wizard comes up choose Connect to an existing database, choose JDBC from the dropdown and then hit Next.
-
Sixth, the Datasource URL is of the form below.
jtds:sqlserver://[host]:[port]/[database]
Replace [host] with the hostname of the server, replace [port] with the port that the database connects over (the default is usually 1433) and replace [database] with the name of the database.
-
Seventh, for the JDBC driver class put in the below.
net.sourceforge.jtds.jdbc.Driver
You can hit Test class if you want to. It should give you a promising message. After all of the fields are filled out hit Next.
-
Eight, on this screen you can fill out the authentication information. This should be pretty straight forward and you can test it to see that it is connecting properly. And then on the last screen you can set some final options and then save the local connected copy somewhere.
After that you should be able to see and browse the tables, build queries and have fun.
- - - - -
You can also use this jTDS driver to connect to Sybase. All you have to change the Datasource URL to this form.
jtds:sybase://[host]:[port]/[database]
- - - - -
For connecting to MySQL you can follow these same steps except you need to get the MySQL JDBC driver class from the MySQL website (http://www.mysql.com/products/connector/j).
The Datasource URL is:
mysql://[host]:[port]/[database]
And the JDBC driver class is:
com.mysql.jdbc.Driver