Code Comments

Code Comments

Tips and short tutorials on various programming technologies

Code Comments RSS Feed
 
 
 
 

Archive for November, 2008

Find the Difference Between Two Lists with Python

Let’s say you have two lists in Python that have a lot of overlap between them.

a = ["abc","def","ghi"]
b = ["def","ghi","jkl"]

Now let’s say you want to determine what is in b that is not in a. In set theory, you would refer to this as the set-theoretic difference of b in a. The following simple code [...] Read more »

Find the Difference Between Two Lists in Java

Let’s say you have two lists in Java that have a lot of overlap between them.

ArrayList a = new ArrayList();
a.add("abc");
a.add("def");
a.add("ghi");
 
ArrayList b = new ArrayList();
b.add("def");
b.add("ghi");
b.add("jkl");

Now let’s say you want to determine what is in b that is not in a. In set theory, you would refer to this as the set-theoretic difference of b in a. [...] Read more »

Enabling PDF File Editing in OpenOffice 3

I heard that the new version of OpenOffice would allow you to edit PDF files. When I heard this, I was thinking you would be able to import a PDF file into OpenOffice Writer and then edit it like you would any other document. I guess it’s not that advanced yet, and it’s not built [...] Read more »

Copy Data From One Table to Another with SQL

Let’s say you have two tables in your SQL database. One is called Table1 and has columns called Column1 and Column2. And the other is called Table2 with columns of the same name. An easy way to copy from Table1 to Table2 would be with the following SQL statement.

INSERT INTO Table1
SELECT * FROM Table2

However, let’s [...] Read more »

How to Get Column Names from Database Table with Java

Let’s say you have a table in a SQL database and you want to discover the names of the columns from Java. One way to do this that is pretty straightforward is with the following code.

import java.sql.*;
 

 
public ArrayList<String> GetColumnNames(String tableName) throws Exception
{
DatabaseMetaData meta = _conn.getMetaData();
ResultSet rsColumns = [...] Read more »

Add an Item to an Array in Java

If you haven’t read this post that talks about the differences between arrays and ArrayLists, that would be a good first step. Typically you would use an ArrayList rather than an array if you want to be able to add and remove objects. However, if you would rather (or are required to) use arrays, this [...] Read more »

How to Install ISO Files Without Burning to a CD

Recently I was trying to install software that had a really large installer. Typical in this scenario, they offer an ISO file, which is typically used to burn a CD, which you can then use to install the program from your CD/DVD drive. However, sometimes you want to be able to install the program without [...] Read more »

Publishing to a WordPress Blog via XML-RPC (Conclusion)

Please refer to this post for some background.
This series of posts has demonstrated how you can send XML-RPC requests to a WordPress server and get back responses. This allows you to do things like automatically post blog entries, modify them, delete them, etc. This is the type of thing that blogging editors do so you [...] Read more »

Publishing to a WordPress Blog via XML-RPC (Part 8)

Please refer to this post for some background.
Now that all the pieces are in place, a class called WordPressClient brings it all together. It has methods that correspond with some of the tasks you might try to accomplish (such as creating a new post, deleting a post, adding a category, etc.).

using System;
using System.Collections.Generic;
using System.Text;
 
namespace Piccolo.Common
{
public [...] Read more »

Publishing to a WordPress Blog via XML-RPC (Part 7)

Please refer to this post for some background.
The next class is used for actually sending and receiving XML-RPC messages over HTTP. I’ve also added some statements that write the requests and responses to Console.Out so you can see what they look like as they are going across the wire.

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
 
namespace [...] Read more »

Publishing to a WordPress Blog via XML-RPC (Part 6)

Please refer to this post for some background.
This section builds on the previous post about regular expressions. When the XML-RPC server sends a response, you need to be able to parse through the XML. The following class can be used for that purpose.

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
 
namespace Piccolo.Common
{
public class WordPressXmlParser
{
public static string[] ParseArray(string result)
{
result = [...] Read more »

Publishing to a WordPress Blog via XML-RPC (Part 5)

Please refer to this post for some background.
After you send a request to the XML-RPC server, it sends a response back to you in an XML structure. You have to parse out the values that are important (for example, whether the request was successful, a new post ID that was generated, etc.)
Again, the .NET Framework [...] Read more »

Publishing to a WordPress Blog via XML-RPC (Part 4)

Please refer to this post for some background.
When you’re sending requests to the server, you have to build text in XML. There are a few ways to do this in C#. One way is to use classes that were designed for this in the .NET Framework. However, I decided not to use these because they [...] Read more »

Publishing to a WordPress Blog via XML-RPC (Part 3)

Please refer to this post for some background.
OK, this post is going to talk about some of the plumbing. When you are sending requests to the server and when the server is replying with responses, you need to deal with key-value pairs. For example, userName = “steve” or password = “abc123″. C# has some classes [...] Read more »

Publishing to a WordPress Blog via XML-RPC (Part 2)

Please refer to this post for some background.
Using XML-RPC, you can create new blog posts, delete posts, edit posts, add categories, delete categories, etc.
XML-RPC operates over HTTP (the protocol we use to access a typical Web page). You send information in a request to the server, and the server replies with a response, telling you [...] Read more »

Publishing to a WordPress Blog via XmlRpc (Part 1)

Please refer to this post for some background on what I’m trying to do here.
Because it’s simple, I’m going to start with a class called WordPressBlogPost. This class holds information about a post–in this case, title, text, and categories. It’s not comprehensive but covers the core information you would need to know about a post.

namespace [...] Read more »

How to Publish to a WordPress Blog Using XmlRpc

This is the first in a series of posts about how to publish to a WordPress blog using an interface called XmlRpc that is supported by WordPress as well as other blogging platforms.
My motivation for writing these posts is that I have a hobby project that is written in the C# language, and I wanted [...] Read more »

Remove an Item from an Array in Java

If you haven’t read this post that talks about the differences between arrays and ArrayLists, that would be a good first step. Typically you would use an ArrayList rather than an array if you want to be able to add and remove objects. However, if you would rather (or are required to) use arrays, this [...] Read more »

Convert an ArrayList to an Array in Java

OK, back on my soap box; this task is somewhat annoying in Java and should be easier.
If you have an ArrayList object and want to convert it to an array of objects, here’s the way to do it with a minimal amount of code.

ArrayList list = new ArrayList();
list.add("abc");
list.add("def");
list.add("ghi");
 
Object[] array = list.toArray();
 
for (Object x : [...] Read more »

Convert an Array to an ArrayList in Java

Sometimes you have an array but would rather use an ArrayList. This post talks about the differences between these. It’s not super straightforward to do this conversion but not too hard either. Here’s how you would do it for strings.

public static ArrayList<String> CreateStringList(String … values)
{
ArrayList<String> results = new ArrayList<String>();
[...] Read more »