programming – Sheep Guarding Llama https://sheepguardingllama.com Scott Alan Miller :: A Life Online Fri, 31 Oct 2008 21:59:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.1 Simple Ruby Twitter Client – Tweet [Ruby] https://sheepguardingllama.com/2008/10/simple-ruby-twitter-client-tweet-ruby/ https://sheepguardingllama.com/2008/10/simple-ruby-twitter-client-tweet-ruby/#comments Fri, 31 Oct 2008 18:41:58 +0000 http://www.sheepguardingllama.com/?p=2833 Continue reading "Simple Ruby Twitter Client – Tweet [Ruby]"

]]>
This is my simple, Ruby based Twitter client using Curl designed for UNIX systems like Linux, Mac OSX, FreeBSD, Solaris, etc.  The only requirements are Curl and Ruby.

In order to use Tweet, simply copy all of the included code into your favourite text editor (I use vi) and save as ‘Tweet’.  Don’t forget to “chmod a+x tweet” so that it is executable.  I suggest moving Tweet into your path (perhaps you should consider /usr/local/bin as a recommended directory) to make it easier to use.  I have designed Tweet to be useful to users on a multi-user UNIX system.  It is a command-line utility that simply accepts text input and posts that text, maximum of 144 characters, to your Twitter account.  An existing Twitter account is necessary so sign up if you do not have one already.

There is very little to know in order to use Tweet [Ruby].  (Should I name this RTweet perhaps?)  The one thing that is needed is to set your username and password.  Tweet [Ruby] is designed to accept username and password data from the system environmental variables $tweetuser and $tweetpass.  This design decision was made because it makes it extremely simple to have multiple users on the same system be able to use Tweet [Ruby] transparently from one another.  If you desire, you can bypass this setting by changing the “unset” user and pass settings in the code to your username and password.  This hardcoding is not recommended but is available if needed.

Once you have your username and password set (you can see what your settings currently are by using the -t option) all you need to do is enter the text that you want to publish.  Here is an example:

tweet ‘This is my first post from Tweet [Ruby].  Thanks Scott, this is great.’

Here is the code, go crazy.

#!/usr/bin/ruby -w
#Scott Alan Miller's "Tweet" - Twitter Command Line Script

text = ARGV[0].chomp
user = "unset"         #Supplied Username
pass = "unset"         #Supplied Password
url  = "http://twitter.com/statuses/update.xml"
ver  = "1.0"

user = ENV['tweetuser'] if ENV['tweetuser']
pass = ENV['tweetpass'] if ENV['tweetpass']

if    text.length <= 0
  puts "Please enter text to post."
elsif text.length >= 144
  puts "Please limit post to 144 chars."
elsif text == "-v"  # Version Message
  puts "Current Version of Tweet [Ruby] is " + ver
elsif text == "-h"  # Help Message
  puts "Tweet [Ruby] Help: \n"
  puts "To set environmental username and password:"
  puts "  export tweetuser=yourusername"
  puts "  export tweetpass=yourpassword\n"
  puts "Usage:"
  puts "  tweet \'This is my message.\'"
elsif text == "-t"  # Variable Test
  puts "Username: " + user
  puts "Password: " + pass
else
  result = %x[curl -s -S -u #{user}:#{pass} -d status="#{text}" #{url}]
  puts "Update Failure" if result.grep(/text/) == nil
end

If you end up using my little Twitter client, please send me a Tweet to let me know!

tweet ‘@scottalanmiller Using Tweet, best Twitter client ever.  Ruby rulz.’

]]>
https://sheepguardingllama.com/2008/10/simple-ruby-twitter-client-tweet-ruby/feed/ 5
Ruby/Qt: qtruby4.rb:2144: [BUG] [x86_64-linux] https://sheepguardingllama.com/2008/10/rubyqt-qtruby4rb2144-bug-x86_64-linux/ https://sheepguardingllama.com/2008/10/rubyqt-qtruby4rb2144-bug-x86_64-linux/#respond Sat, 04 Oct 2008 17:01:50 +0000 http://www.sheepguardingllama.com/?p=2661 Continue reading "Ruby/Qt: qtruby4.rb:2144: [BUG] [x86_64-linux]"

]]>
You are working with Ruby and Qt and you get the following error:

/usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation fault
ruby 1.8.6 (2008-03-03) [x86_64-linux]

This is usually caused by a library linking problem. Most likely you are using:

require 'Qt'

Personally, I run into this problem when using Ruby/Qt on Novell OpenSUSE 11 64bit (x86_64 / AMD64).  What needs to be done is that linking needs to occur explicitly to the correct library.  If you are using ‘Qt3’ then you can link directly to that or, in my case, you want to use Qt4/KDE4 bindings then you will want to link to korundum4:

require 'korundum4'

Problem solved!

Thanks to Bemerkenswertes Meinerseits for some guidance in German!

]]>
https://sheepguardingllama.com/2008/10/rubyqt-qtruby4rb2144-bug-x86_64-linux/feed/ 0
Robert Dewar on Java (and College) https://sheepguardingllama.com/2008/08/robert-dewar-on-java-and-college/ https://sheepguardingllama.com/2008/08/robert-dewar-on-java-and-college/#respond Mon, 04 Aug 2008 23:43:10 +0000 http://www.sheepguardingllama.com/?p=2478 Continue reading "Robert Dewar on Java (and College)"

]]>
Two recent interviews with Prof. Robert Dewar of NYU, Who Killed the Software Engineer and The ‘Anti-Java’ Professor, have recently been popular on the web and I wanted to add my own commentary to the situation.  These interviews arise from Dewar’s article in the Software Technology Support Center: Computer Science Education: Where are the Software Engineers of Tomorrow? As someone who takes his role on a university computer science / computer information systems professional review board very seriously, I have spent much time considering these very questions.

Firstly, Prof. Dewar is hardly alone in his opinion that Java, as an indicator of the decline of computer science education in America, is destroying America’s software engineering profession.  The most popular example of someone with similar opinions would, of course, be the ubiquitous Joel Spolsky (of Joel on Software fame) in his Guerrilla Guide to Interviewing or in Stack Overflow Episode 2.

The bottom line in these arguments is not against Java but about the way in which colleges and universities teach computer science.  Computer Science is an extremely difficult discipline, but universities will often substitute simple classes for core CS classes.  Dewar states that this is widely because enrollment has dropped off in these programs as the field is less attractive and students choose lower-hanging educational fruit.  Universities put pressure on the departments to increase enrollment, often by lowering standards and eliminating hard requirements.  However, difficult programming classes like deep C or Assembler, require more highly trained, and therefore expensive, resources so this too causes academia to avoid teaching such categories.  A trained C or C++ developer has much better compensation prospects in the “real world” than they do in academia.

Java itself is a great language and no one, in this case, is saying that Java is not or should not be popular in real world development.  But Java is a language designed for rapid software creation and includes a staggering amount of built in libraries.  Almost anything truly difficult has been addressed by Sun’s own highly skilled developers already and does not require reworking by a working developer.  Working with Java requires only a rudimentary knowledge of programming.  This, by its very nature, makes using Java as a learning environment a crutch.  Learning to program in Java is far too easy and many, perhaps most, programming concepts can be easily avoided or perhaps missed accidentally.  (Anything that I can say here could apply to C# as well.  Both are great languages but extremely poor for teaching computer science.)

Far too often university computer science programs teach no language but Java.  Computer science students need many things including deeper system knowledge and a more widespread knowledge of different languages.  Computer science programs need to stop focusing on single, limited skill sets and start teaching the field of CS, and students need to stop accepting the easy way out and demand that their schools live up to the needs of the workplace!

While, by and large, I agree with Dewar whole-heartedly, he does have one comment that I find very disturbing – although very unlikely to be wrong.  He mentions, in more than one place, that Java is inappropriate as a “first language” as if computer science students at NYU and other universities are learning their first programming languages in college! This is an incredibly scary thought.

I guarantee that international students looking at careers in software engineering or computer science wouldn’t think of entering university without a substantial background in programming.  I can’t imagine a school like NYU ever considering such a case.  If we are allowing the entrance bar to be set so low than can we even possibly consider what we teach when apparently it matters very little?  Would we accept college students who didn’t do algebra in high school?  Didn’t speak English?  Know no history?  Failed physics?  How then could we possibly consider allowing non-programmers into what should be one of the most difficult possible collegiate programs available, and how can we expect good, proficient programming students to learn something of value when forced to learn alongside new learners?

Dewar’s argument for the necessity of a higher standard of collegiate computer science education is that by dumbing down the curriculum and handing out meaningless degrees to anyone willing to pay for them (hasn’t this been my argument against the university system all along?) we are fooling outselves into believing that we are training tomorrow’s workforce when, instead, we are simply accelerating the rate of globalization as developing countries see a massive opportunity to invest in core disciplines and outpace the United States at breakneck pace.  Software development is a field with very little localization barrier inherent to the work and is a prime candidate for offshoring due to the nature of the work and the advanced communications commonly associated with its practitioners and the higher level of skills generally present in its management.  But by created a gap in the American education system we are making a situation occur that simply begs to be globalized as our own country is mostly unable to produce qualified candidates.

Lacking from many discussions about computer science curriculum is the need to discuss the range of IT curricula in programs such as IT and Computer Information Systems.  Computer Science is a very specific and very intense field of study – or so it is intended.  Only a very small percentage of Information Technology professionals should be considering a degree program in CS.  This is not the program for administrators, managers, network engineers, analysts, database administrators, web designers, etc.  Even a large number of programmers should be seriously considering other educational avenues rather than computer science.

There is a fundamental difference in the type of programming that a comp sci graduate is trained to perform compared to a CIS graduate, for example.  CIS programs, even those targetting programming, are not designed around “system programming” but are generally focussed around more business oriented systems often included web platforms, client side applications, etc.  CS is designed to turn out algorithm specialists, operating system programs, database programmers – the kind of professionals that companies like Microsoft, Oracle and Google need in droves but not the type that the 300 seat firm around the corner needs or has any idea what to do with.  Those firms need CIS grads with a grasp of business essentials, platform knowledge and the ability to make good user interfaces rapidly.  These are very different job descriptions and the best people from either discipline may be pretty useless at the other.

All of this points to the obvious issue that companies need to start thinking about what it means to higher college graduates.  If all but a few collegiate programs are allowing CS programs to be nothing more than a few advanced high school classes in Java – why are we even looking at college degrees in the highering process?  Highering practices need to be addressed to stop blindly taking university degrees as having some intrinsic value.  We are in an era where the universities are wearing the emporer’s new clothes.  Everyone knows that the degrees are valueless but no one is willing to say it.  The system depends on it.  Too many people have invested too much time and money to admit now that nothing is being taught and that students leaving many university programs are nothing more than four or five years behind their high school friends who went straight to work and developed a lifelong ability to learn and advance rather than to drink beer while standing on their heads and spent their parents’ or borrowed money.

Computer Science departs need to start by developing a culture of self respect.  Teaching Java is not bad but a CS grad should have, perhaps, one class in Java and/or C# not a curriculum based around it.  Knowledge of leading industry languages like Java is important so that students have some feel for real world development but a CS degree is not preparing many students for work in Java based application development but for systems programming which is almost exclusively in C, C++ or Objective-C.

]]>
https://sheepguardingllama.com/2008/08/robert-dewar-on-java-and-college/feed/ 0
June 20, 2008: Introducing HandBrake Helper https://sheepguardingllama.com/2008/06/june-20-2008-introducing-handbrake-helper/ https://sheepguardingllama.com/2008/06/june-20-2008-introducing-handbrake-helper/#respond Sat, 21 Jun 2008 09:29:02 +0000 http://www.sheepguardingllama.com/?p=2417 Continue reading "June 20, 2008: Introducing HandBrake Helper"

]]>
Oreo was incredibly tired as Dominica dragged him off to daycare this morning. He was giving me the big, sad puppy dog eyes saying “save me daddy” which he does when he really, really wants to just stay home and sleep. He doesn’t know that on days when he goes to daycare that I get up as he walks out the door and start working right away. He imagines that after he leaves that I stay in bed and he just wants to snuggle all morning.

We managed to do so much Handbraking that we are running out of storage space – which is a big deal since I have half of a terabyte on my main desktop reserved for h.264 files and am using a bit of space over on my other desktop as well.  I have to start moving files out to the Netgear SC-101 SAN drives now.  We have an additional one terabyte there but access to it is painfully slow and less reliable so we don’t want to store anything there that we want to access anytime soon or that we are worried about losing.  Our plan is, after we get a house, to install a large server dedicated to our media archives that will have lightning fast access to everything all in one spot.  We are hoping to be able to install around eight to twelve terabytes there  as that is pretty likely to be what we will need in the short term to power our AppleTV(s).

I kicked off the download of OpenSuse 11.0 this morning.  It is still early and people are trying hard to get their own copies so the downloads are pretty slow but at least I have it running.  Maybe by tomorrow I can try an installation.  I am doing the download over BitTorrent which isn’t the fastest way to get it, yet, but at least I am contributing to making the system faster so that other people can get it that much more quickly.

My work day was pretty long.  I started at ten after seven this morning and my deployments were not completed until almost eight in the evening.  We ordered in Chinese for dinner from Golden City.  They ran out of tofu so there was only enough to make Dominica’s dinner but not mine.  So I had vegetable fried rice and extra spring rolls and cheese wontons which was a bad idea as it gave me a tummy ache which would get me up in the middle of the night for quite a while.

We watched more Third Rock from the Sun tonight.  I also started work on a neat little Ruby command line application that makes doing a large number of Handbrake jobs easier.  I call it HandBrake Helper.  The design is to have folders into which you can drop files to be processed by HandBrake.  Each folder has a configuration file in it telling HandBrake what settings should be used for files in that folder.  Then you just place your files to be converted into the appropriate folder and kick off HandBrake Helper and it automatically processes your files for you and cleans up after itself.  I just started work on it this evening but had enough done that it is now running the HandBrake jobs on my Linux machines.  I was able to kick it off before going to bed so that it would work through the night for me.  Using HandBrake Helper makes doing conversions much more convenient and it keeps track of my preferred settings so that I don’t have to enter them every time hoping that I don’t get them wrong.

Tomorrow Dominica and I are going in to Manhattan around eleven in the morning to meet up with Nathan, Tammy, Bob, Lisa, Eric and other friends from Ithaca at Planet Hollywood for lunch.  Then it is on to see Mary Poppins on Broadway at a matinée.

]]>
https://sheepguardingllama.com/2008/06/june-20-2008-introducing-handbrake-helper/feed/ 0
Singleton Pattern in C# https://sheepguardingllama.com/2008/05/singleton-pattern-in-c/ https://sheepguardingllama.com/2008/05/singleton-pattern-in-c/#comments Fri, 09 May 2008 22:02:16 +0000 http://www.sheepguardingllama.com/?p=2370 Continue reading "Singleton Pattern in C#"

]]>
Implementing the Gang of Four Singleton Pattern in Microsoft’s C# .NET language is nearly identical to its Java implementation. The Singleton Pattern (as definied by the Gang of Four in 1995) is to “ensure a class only has one instance, and provide a global point of access to it.”

The idea behind the Singleton pattern is that there can only be one unique object of the class in existence at any one time. To make this possible we must make the constructor private and instead create a public “get” accessor for the Instance reference that controls access to the constructor, returning a new object if none exists or returning the already instantiated object if one does.

Here we have an example of the simplest possible Singleton class which I call, Singleton. It has only those methods absolutely necessary for the pattern and one console print statement in the constructor so that we can easily see when the constructor is called. I have opted to include Singleton and TestSingleton, its testing harness, in a single file. This allows me to easily demonstrate how to create the Singleton pattern and how to instantiate a Singleton object from outside the class.

TestSingleton.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SingletonPattern
{
    class TestSingleton
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Calling First Instance: ");
            Singleton mySingleton = Singleton.Instance;
            Console.WriteLine("Calling Second Instance: ");
            Singleton myOtherSingleton = Singleton.Instance;
        }
    }
    public class Singleton
    {
        private static Singleton instance;
        private Singleton()
        {
            Console.WriteLine("Singleton Constructor Called");
        }
        public static Singleton Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new Singleton();
                }
                return instance;
            }
        }
    }
}

Microsoft has a great article discussing the Singleton Pattern and its common variations as they pertain to the C# language in the MSDN Patterns and Practices Developers Center – Implementing Singleton in C#.

Also see: Sheep Guarding Llama Singleton Pattern in Java

]]>
https://sheepguardingllama.com/2008/05/singleton-pattern-in-c/feed/ 1
Singleton Pattern in Java https://sheepguardingllama.com/2008/05/singleton-pattern-in-java/ https://sheepguardingllama.com/2008/05/singleton-pattern-in-java/#comments Fri, 09 May 2008 18:58:02 +0000 http://www.sheepguardingllama.com/?p=2369 Continue reading "Singleton Pattern in Java"

]]>
Implementing a Singleton Class Pattern in Java is a common and easy task. The Singleton Pattern (as definied by the Gang of Four in 1995) is to “ensure a class only has one instance, and provide a global point of access to it.”

The idea behind the Singleton pattern is that there can only be one unique object of the class in existence at any one time. To make this possible we must make the constructor private and instead create a public getInstance() method that controls access to the constructor, returning a new object if none exists or returning the already instantiated object if one does. We must also override the clone() method from the Object superclass as this oft forgotten method will provide a workaround to our Singleton protection.

Here we have an example of the simplest possible Singleton class which I call, Singleton. It has only those methods absolutely necessary for the pattern and one console print statement in the constructor so that we can easily see when the constructor is called.

Singleton.java

public class Singleton {
     private static Singleton instance;
     private Singleton() {
          System.out.println("Singleton Constructor Called");
     }
     public static synchronized Singleton getInstance() {
          if (instance == null)
               instance = new Singleton();
          return instance;
     }
     public Object clone() throws CloneNotSupportedException {
          throw new CloneNotSupportedException();
     }
}

Now that we have a working Singleton class we need to make a simple test harness to see how we can call it and how it behaves. In our test we will simply create two objects, mySingleton and myOtherSingleton and we will see when the constructor method is called.

TestSingleton.java

public class TestSingleton {
        public static void main (String[] args) {
                System.out.print("Calling First Instance: ");
                Singleton mySingleton = Singleton.getInstance();
                System.out.print("Attempting to Call Again: ");
                Singleton myOtherSingleton = Singleton.getInstance();
        }
}

Hopefully this will help you write quick and easy Singleton pattern classes in the future.

See also: Sheep Guarding Llama Singleton Pattern in C#

]]>
https://sheepguardingllama.com/2008/05/singleton-pattern-in-java/feed/ 1