Pueblo Computing

TwitterVB 2.9.x: Now with UpdateProfileImage

by on Sep.23, 2010, under programming

Twitter-2.9.9

Okay, we were a bit late to the party (blame schedules and stuff), but TwitterVB now has the ability to Update your profile image from a third party app or web site.  This will continue to make TwitterVB a fantastic tool for Visual Basic programmers looking for a native way to add social networking tools to their applications.

At this point, we have a number of things we could go about, the #twitter could be one of them.  Personally, I’m wondering if it isn’t time to add another project or two; in particular, I want to start developing a native Delphi Twitter library.  If anybody else is interested, fill out the contact form and let me know.

Leave a Comment :, , , more...

Twistakes 101: What to do if your code goes wrong.

by on Sep.15, 2010, under programming

By the way, forgive me the awful twun.  When talking twitter, sometimes I just can’t twelp. . .nevermind.

If we all could write perfect code the first time, we’d be making as much money as Bill Gates (or he would be making as much as the rest of us).  Sadly, this isn’t the case a lot of the time; even when you’re using an awesome library like TwitterVB.

While some errors are truly bizzare, a lot of the errors are common and things that you will see in the TwitterVB discussions. Here’s my list of the errors and how to fix them.

Using a different instance of the TwitterAPI class to validate a PIN than the one used to generate the URL.

Suppose we have the following code:

Imports TwitterVB2

Module Module1
   

    Sub Main()
        Dim strURL As String
        Dim strPIN As String

        strURL = GetLinkURL()
        Process.Start(strURL)
        Do
            Console.Write(“Input PIN: “)
            strPIN = Console.ReadLine()
        Loop Until isValidPIN(strPIN)
        Console.WriteLine(“This will never happen”)
        Console.ReadKey()

    End Sub

    Function GetLinkURL() As String
        dim tw1 as new TwiterAPI
        Return tw1.GetAuthorizationLink(“consumerkey”, “consumersecret”)

    End Function

    Function isValidPIN(ByVal p_strPIN) As Boolean
       dim tw2 as new TwitterAPI
        Return tw2.ValidatePIN(p_strPIN)

    End Function
End Module

Run that code in Visual Basic (just create a new console application), and run it.  I can tell you that with the code as is, you will never reach the line that says “this will never happen”.

A quick look at the TwitterAPI code will tell you why:

Public Function GetAuthenticationLink(ByVal ConsumerKey As String, ByVal ConsumerKeySecret As String) As String
            Me.Twitter_OAuth = New TwitterOAuth(ConsumerKey, ConsumerKeySecret)
            Return Me.Twitter_OAuth.GetAuthenticationLink
        End Function
. . .

 Public Function ValidatePIN(ByVal PIN As String) As Boolean
            Return Me.Twitter_OAuth.ValidatePIN(PIN)
        End Function

Since the TwitterAPI is validating against the Twitter_OAuth object it filled with the first function, having two instances will guarantee a fail.  Also, the comments note that you must call GetAuthenticationLink() first.  This makes the first code unusable in its current state.

So how do you write this code so it goes through?  One possible solution involves setting the TwitterAPI object at module or class level.  Observe:

Module Module1
    Dim twConn As New TwitterAPI

    Sub Main()
        Dim strURL As String
        Dim strPIN As String

        strURL = GetLinkURL()
        Process.Start(strURL)
        Do
            Console.Write(“Input PIN: “)
            strPIN = Console.ReadLine()
        Loop Until isValidPIN(strPIN)
        Console.WriteLine(“This will never happen”)
        Console.ReadKey()

    End Sub

    Function GetLinkURL() As String

        Return twConn.GetAuthorizationLink(“consumerkey”, “consumersecret”)

    End Function

    Function isValidPIN(ByVal p_strPIN) As Boolean

        Return twConn.ValidatePIN(p_strPIN)

    End Function
End Module

This code will run seeing as how the same object created the authorization link and validated the returned PIN.

Leave a Comment : more...

Twitter: Basic auth is yesterday, oAuth is here to stay

by on Sep.02, 2010, under programming

Twitter ending Basic Auth

We’ve known that this day was coming, and as of August 31, that day was yesterday. No longer will third-party applications be able to use Basic authentication, which transmits username/password combos in plain text. Rather, Twitter clients will have to utilize a system known as oAuth. This system uses tokens which are generated based upon information passed by the application and the user’s okay.

While this system is safer in terms of user information, it does present problems for some developers. Namely, the fact that this requires a web browser will cause some consternation to some developers. However, I think that most developers will eventually learn to adapt around these limitations. Neither do I buy the argument that I have seen around the web that this will somehow squeeze small developers. Bull. The oAuth standard is open and there are already several Twitter libraries that implement the oAuth standard.

Another complaint I have heard involves Open Source.  Several have complained that the nature of Open Source requires them to disclose their consumer key combos (the keys that developers use to generate the Tokens).  Thus, a rogue programmer could hijack a set of keys and use them for spamming which would get the innocent programmer kicked.  This is a misunderstanding of Open Source.  Open Source only requires you to disclose the source code; it does not require you to disclose the information.  Programs can be written without hard coding the consumer key or consumer key secret.  Even if you do it is relatively simple to distribute the binary file with the keys and the source without it.

Ultimately, however, it is Twitter’s service.  Developers that are looking to hook their product onto Twitter will have to develop around these limitations.

Leave a Comment :, , , more...

Good Computerkeeping

by on May.14, 2010, under computers

Well, I’ve started some computer related tasks today.  Most of them are housekeeping, which I am horrible at.  But a lot of these tasks need to be done.

  1. Changing passwords: Now I’m not a big password changer. First off, frequently changing your passwords is pretty much a waste of time. However my choices for passwords have been a little bit substandard. So I needed a way to change them. Again, not my favorite task. Enter infinite password generator. Just enter a master password and a keyword and you are set up. Easy enough for even the most oblivious user.
  2. Automating backups: I admit I’m a bit better at backups, but they are still something that I do manually. In particular backing up my Thunderbird and Firefox profiles with Mozbackup. BTW if you don’t have this tool and use either one of the above Mozilla products, what are you waiting for?. As to where to back them up to, I normally have those profiles backed up to my Dropbox, which is mapped to my file system. So I figured that I would automate mozbackup to do this every day. Thankfully mozbackup has command line options to do this. So I used Windows Task Scheduler to set this up at a time when I wasn’t using the program.
    Which brought me to my next problem: Mozbackup will not work if you have the program you want to back up open. So I needed to kill the program, if it is running. One Google search later I ran across the TASKKILL command. So I set up a batch program to kill off thunderbird if it is running.

And what are you doing for your computerkeeping?

Leave a Comment :, , , , more...

This Adobe-Apple bitchfight is getting more interesting

by on May.10, 2010, under technology

Report: Apple developing a Flash alternative | Apple – CNET News

The heated battle between Apple and Adobe Systems over Flash may get a bit more interesting, as reports of a Flash alternative being developed by Apple begin to surface.
(Credit: Apple)

The technology, called Gianduia, was introduced by Apple last summer at its World of WebObjects Developer Conference, according to an AppleInsider report. Gianduia is described as being “a client-side, standards-based framework for rich Internet apps.”

I’ll admit, I was intrigued by the Apple-Adobe slap fight if only for the sheer balls of the thing. I mean, Mr. Jobs telling somebody else to use “open standards”. As in Steve Jobs, the head of Apple. The head of a company that has had both its hardware and software in such a lockdown mode that if it weren’t for the fact that it’s market share was so small the DOJ would have broken it up decades ago (and it still might be investigated for possible anti-trust violations still.

Now there’s this, which could be compared to Microsoft’s creation of C# to get around having to license Java. Look,I’m always interested in new frameworks, but if this is just Apple’s way of pushing Adobe around and sending a message to all developers that it’s “Jobs way or the high way” then no thank you Steve.

Leave a Comment :, , , more...

One backup service I definitely recommend

by on May.10, 2010, under reviews

Online Backup – IDrive – Remote Data Backup – For Windows and Mac – IDrive Portable Hard Drive

Backing up data is easy. The hard part comes when you have to restore that data, and that’s where IDrive really does shine.

A couple of days ago I had to reinstall my hard drive. It happens from time to time, especially when you are downloading and testing a lot of different applications. Unfortunately, I forgot to make a local copy of the things that were the most important to me: namely, the applications I had written and my documents. This is stuff that isn’t exactly replaceable. After the typical panic I remembered that I had tried out IDrive and logged back in. Lo and behold, I was able to quickly restore those documents. Just a click and a checkmark and I was in business. IDrive is one of those services that you have to try. It starts out with a 2 GB limit but you can push that up to 12 with a promotional e-mail sent out. Best of all, you can schedule the backup to when you are not actively surfing the Internet. I would sign up for this service today.

 

Leave a Comment :, , , more...

How Not to Use Powerpoint

by on May.01, 2010, under Uncategorized

Rack this video:

Leave a Comment more...

xAuth (Part 1)

by on Apr.30, 2010, under programming

Earlier this year, Twitter announced that it would be ending support of Basic Authentication (or Authentication through a username/password combination). The date has now been set as April 30, 2010. As of that date, basic authentication will no longer be allowed and all apps connecting to Twitter will be required to use oAuth.

One problem with transferring from Basic to xAuth is with applications who use a lot of different accounts for legitimate purposes. These may be web applications used for a lot of different people OR desktop apps installed on a lot of computers. A lot of these computers still have the username/password. To make it easier to transition Twitter is offering xAuth access. xAuth generates the tokens through the user of the applications own consumer keys (public and secret) and the username/password combination. These can be sent without use of a browser, which can be good for programs residing on servers and other devices that don’t have human interaction. And now you can convert your application over with the latest version of TwitterVB, 2.5. By using TwitterVB you can isolate yourself from the messy business of generating http signatures and proper encoding and focus on your application.

How to transfer?

Before you transfer you need to get permission for your application to use xAuth. If you do not, any code you write based on what is below will bounce off with a 401 unauthorized error. Before that, however, you need to set up your application to use oAuth. Visit Twitter.com and register your client application. You’ll need the client’s name, function, URLs, and whether it just needs read access or read/write access. Once you fill that out you will be presented with a page with two long strings, the consumer key and the consumer secret. These are needed to sign your requests.

There’s also one other number you should write down. The URL will have a  number at the end is your application’s ID. That will be very important in order to turn on xAuth access in a moment. Next, we need to ask permission for your app to access xAuth. Send an e-mail with the ID, name of your app, and a description of why your app needs xAuth (either permanently or temporarily) to api at twitter dot com. Typically you can expect a response within 8 business hours.

How to implement

For the following examples. I am going to create a simple Console application that logs in, prints everything off my public timeline, and leaves. I create the console application, and then I go into the project settings and set four string variables:
*m_strConsumerKey
*m_strConsumerSecret
*m_strToken
*m_strTokenSecret
These will all be accessed through the My.Settings namespace. I set the ConsumerKey and ConsumerSecret to what I received on the page where I registered my program and added a reference to TwitterVB (making sure that it’s at least the 2.5 version)

Next, I write the following code:

Imports TwitterVB2

Module Module1

    Sub Main()        Dim twConn As New TwitterAPI        Dim strPassword As String        Dim strUserName As String

        Try

            If My.Settings.m_strToken.Trim.Length = 0 Then                Console.Write("Input Username: ")                strUserName = Console.ReadLine()                Console.Write("Input Password: ")                strPassword = Console.ReadLine()                twConn.XAuth(strUserName, strPassword, My.Settings.m_strConsumerKey, My.Settings.m_strConsumerSecret)                My.Settings.m_strToken = twConn.OAuth_Token                My.Settings.m_strTokenSecret = twConn.OAuth_TokenSecret                My.Settings.Save()            Else                twConn.AuthenticateWith(My.Settings.m_strConsumerKey, My.Settings.m_strConsumerSecret, My.Settings.m_strToken, My.Settings.m_strTokenSecret)            End If

            For Each twStat As TwitterStatus In twConn.UserTimeline

                Console.WriteLine(twStat.ID.ToString() & ":" & twStat.Text)            Next            twConn.Update("Read timeline at " & DateTime.Now.ToString)

            Console.ReadKey()        Catch ex As TwitterAPIException            Console.WriteLine(ex.Message)            Console.ReadKey()        Catch ex As Exception            Console.WriteLine(ex.Message)            Console.ReadKey()        End Try

    End Sub

End Module

Run it the first time, and the user will be asked for their name and password. Run it again, and it shouldn’t have to ask for anything. It will just authenticate like any normal oAuth app browserlessly because it already has the tokens. You’ve now set up your application to use oAuth and haven’t had to open a browser window to do it either.

Caveats

By using xAuth, you are agreeing not to store the username/password combination. Once you receive the information you should delete that as a combination so that it cannot be used by somebody else. Done properly, you shouldn’t have to use this more than once for any given account. Caching user information such as the username, screenanme, etc should be okay and in fact encouraged to conserve on rate limits.
Also, while web applications can use xAuth they can only use it on a temporary basis to batch convert existing accounts on over. This means that before you ask for xAuth you should convert your site over so that it can use oAuth, then ask for xAuth access to batch convert existing accounts. Once you have converted them you should at least delete the passwords and at that point be set for using oAuth on a permanent basis.
Finally, while desktop or mobile apps may be granted a more permanent use I would not count on it. The goal should be to convert existing accounts. If there is any way to use a browser on your system then do so. Document every reason why you cannot (aesthetics probably won’t be accepted) before you request permanent xAuth.

Conclusion

With the countdown to the shutdown of Basic authentication, many applications are finding themselves stuck between a rock and a hard place. XAuth in TwitterVB should help you transition more smoothly as long as you remember it’s should only be counted on as a temporary help unless you are notified otherwise by Twitter.

Leave a Comment :, , more...

Aaannnnddd he misses the point by a country mile.

by on Apr.15, 2010, under plagarism

Turnitin privacy worries? Then stop plagiarizing | Education IT | ZDNet.com

Want to avoid this level of scrutiny? Write your own bloody papers. Who knows? The $40,000 a year education might teach you something more than Googling 101 or Advanced Cut and Paste. The very fact that Turnitin exists and is deemed necessary by so many educators fires me up. Regular readers will know that I’m all about Google. It’s a brilliant resource, as is Wikipedia and the other billion or so pages of non-junk on the web. However, students should be able to not only find information, but differentiate the good from the bad and then use it to form their own ideas, in their own words.

The point is not about students not wanting their works to be checked against some sort of database (though I will concede cheaters probably wouldn’t want it too). The point is what happens to the piece after the check. Namely, the fact that the service, turnitin, stores the papers without the express consent of the authors.

Turnitin’s justification for this is rather hilarious:

 

Further, because student works become part of the database against which other students’ work is compared, Turnitin helps protect the papers from being exploited by others who might profitably claim them as their own work, or sell them to other students.

That’s like saying a thief who steals your credit card numbers then stores them in a safe is not only not stealing, but helping you since the safe can’t be broken by other robbers. Thanks, but no thanks.

Look, 90% of student work is probably overall crap. I know mine was and I’m lowballing the estimate. Even where it wasn’t I’d probably polish it a little more before I went to a publishing house. So I’m not thinking that some student might accidentally publish the Great American Novel and turnitin steals it. But I do think that if you’re going to use the papers to profit off of your service and you are using the entire paper (as opposed to a minimum to illustrate as the above) maybe you should ask them nicely. Maybe you should even kick them off something for their efforts.

Leave a Comment :, , more...

Storing persistant data: A primer

by on Apr.09, 2010, under programming

If you are a beginner, chances are that you haven’t been working with storing and using persistent data in between sessions. In fact, most of your apps probably have been the simple type that start in the same state every time you use them. While this is okay when you are learning how to program, the fact remains that you want to store what you did and pick up where you were at a later time. Can you imagine writing out the Great American Novel, exiting your word processor and then having to type the whole thing over again when you booted back up? I don’t think the computer revolution would have gotten far if that happened.

 

Visual Basic, like other languages, provides a number of ways to persist data by storing it. The list is pretty long, but for right now we’ll divide them into the Applications Settings file, a file on the hard drive, and the registry. Each of these ways provides a way to persist the data and each has its ideal purposes.

 

The app.settings

 

To illustrate what I am talking about, fire up Visual Basic.NET (or SharpDevelop if you prefer), create a console Application, and enter the following:

 


Module Module1

Sub Main()
Dim i_Total As Integer
Console.WriteLine("Total at start=" & i_Total)
Dim a_inx As Integer

Do
Console.Write("Enter a number (-1 to quit)")
a_inx = CInt(Console.ReadLine)
If (a_inx > -1) Then
i_Total = i_Total + a_inx
End If
Loop Until a_inx = -1
Console.WriteLine("Total is " & CStr(i_Total))
Console.ReadKey()

End Sub

End Module

 

Run it one time, and type in some random numbers. It doesn’t really matter what numbers you type. Just write out the total it gives you at the end. Now, close it and start again. Did you notice that total started at 0 again? That’s because as soon as the application terminated the GC wiped out all those values in memory. While that may be good for some cases, if you are wanting to keep a total over a number of days and aren’t planning on keeping the program up and running all the time, you need to store that data. RAM is very fast storage but as soon as the power is off, or somebody deletes something, that information is gone. So, how do you store it?

 

In Visual Basic, go to Project->Settings menu item. This will bring up a screen with all sorts of settings. For now, we’re going to ignore them. Click on the Settings sidetab. You should now see a grid to the right. This is where you can set down certain variables that will be written to file.

 

Create a new setting called "i_Total" as an Integer. It will initialize to a zero value. Now modify your code this way:


Sub Main()
Dim i_Total As Integer
If My.Settings.i_Total > 0 Then
i_Total = My.Settings.i_Total
End If
Console.WriteLine("Total at start=" & i_Total)
Dim a_inx As Integer

Do
Console.Write("Enter a number (-1 to quit)")
a_inx = CInt(Console.ReadLine)
If (a_inx > -1) Then
i_Total = i_Total + a_inx
End If
Loop Until a_inx = -1
Console.WriteLine("Total is " & CStr(i_Total))
My.Settings.i_Total = i_Total
My.Settings.Save()
Console.ReadKey()

End Sub

 

Run the app. You’ll notice that it says 0. Enter random numbers like before then -1 to break the loop. Note down the total. Now run it again. The starting value should now be the same as the ending value. This is because you told the program "If I have stored this value in the past, load it into my variable. Add some integers, and once complete save the new total to the disk in a user.config file

 

So where does it get stored? If you check the directory of your program, you won’t find it there. What you will find is an <app>. XML file, which will read something like this:

<userSettings>
        <Settings_Test.My.MySettings>
            <setting name="i_Total" serializeAs="String">
                <value>0</value>
            </setting>
        </Settings_Test.My.MySettings>
    </userSettings>

So where did it store that value? It stored it in a user.config XML file underneath your application folder (AppData for Vista, Application Data for Windows XP).  Note, in order to see this folder you have to update the options for your file viewer to show hidden files.  once there, you will find something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <userSettings>
        <Settings_Test.My.MySettings>
            <setting name="i_Total" serializeAs="String">
                <value>178</value>
            </setting>
        </Settings_Test.My.MySettings>
    </userSettings>
</configuration>

That’s where your value is.  You can edit that value even if you are not in the program. Type a number in where the value is, save it, then rerun the program.  The program will give you the new changed value now.

You can store more than just numbers in the settings file.  For instance, open the project settings page like we did before and enter a new variable strName (leave it blank).  Now modify the code to the following:

Module Module1

    Sub Main()
        Dim i_Total As Integer
        If My.Settings.i_Total > 0 Then
            i_Total = My.Settings.i_Total
        End If

        If My.Settings.strName.Trim.Length > 0 Then
            Console.WriteLine("Hello, " & My.Settings.strName & " Get ready to add.")
        Else
            Console.Write("I don’t know who you are, could you enter your name?")
            My.Settings.strName = Console.ReadLine
            My.Settings.Save()

            Console.WriteLine("Thank you " & My.Settings.strName)
        End If
        Console.WriteLine("Total at start=" & i_Total)
        Dim a_inx As Integer

        Do
            Console.Write("Enter a number (-1 to quit)")
            a_inx = CInt(Console.ReadLine)
            If (a_inx > -1) Then
                i_Total = i_Total + a_inx
            End If
        Loop Until a_inx = -1
        Console.WriteLine("Total is " & CStr(i_Total))
        My.Settings.i_Total = i_Total
        My.Settings.Save()

        Console.ReadKey()

    End Sub

End Module

Fire up the program again.  On the first time through it should ask for your name.  On the second time through it should retrieve the name and the number and pick up right where you belong.

Settings are commonly used for single, short items of memory. Logins, passwords, etc.  Note that by themselves they have a disadvantage:  if you store information in that file without any sort of encryption any other program can come along and read and even modify those variables.  Therefore you should take precautions to ensure that you are not being fed junk (this is especially true with things like connection strings to databases).

App.Settings is a great place to store the value of variables that you wish to persist over time.  But it’s not the only place.

 

Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Archives

All entries, chronologically...