Wednesday, June 24, 2009

Google Android is pretty super easy

I've been messing around with my new toy: a HTC Magic cellphone running Google Android. I was lucky enough to get one for free from Google IO last month and have just finally gotten around to actually writing a little app for it. I haven't done anything terribly difficult yet, but from what I have already accomplished in an hour, I can say it has been a breeze.

One thing that wasn't quite as trivial as I was hoping was making an alert dialog box to do some simple runtime debugging. Understanding how it works now makes this much easier, but here is my one-liner:

(new AlertDialog.Builder(this)).setTitle("An Alert")
.setMessage("Some message")
.create().show();

the "this" in my case is my current Activity which is the default class you make when you start a project which extends the necessary Context class (not directly though). This was inside an event handler (which was implemented as an anonymous inner class) so I had to make a named reference to "this" inside the Activity scope so it was the Activities scoped "this" instead of the anonymous inner class's.

Here is the whole relevant code:


package com.gleenn.android;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class GlennsFirstApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.Button01);
final GlennsFirstApp gfa = this;
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String twitterUsername = ((EditText)findViewById(R.id.EditText_twitter_username)).getText().toString();
String twitterPassword = ((EditText)findViewById(R.id.EditText_twitter_password)).getText().toString();
String statusMessage = ((EditText)findViewById(R.id.EditText_status_message)).getText().toString();
(new AlertDialog.Builder(gfa)).setTitle("Test")
.setMessage(twitterUsername + " " + twitterPassword + " " + statusMessage)
.create().show();
}
});
}
}

Labels: ,

Sunday, May 17, 2009

I <3 MGMT and Finding MWE's



I'm a horrible horrible sell-out and I love this friggin MGMT video. It is so hipsterish and popular, but damn its catchy and the student who made the video did a great, albeit strange, job. I'm also enjoying Electric Feel by them too. Both the vids are definitely helping stay awake and focus on my Python program for my linguistics class.

In my ling class we are writing a program to search for MWE's, or Multi Word Expressions like "kick the bucket" or "stay on track" etc. Turns out it is really hard to get a computer to find these, but ask anyone on the street for some expressions and they'll list a good boat-load out easily. All of it is really fun though, I just wish I had more time to use MapReduce to make my program be able to divide up the work of scanning the corpus of words much faster, as Google does. Maybe in my next lifetime, or at a job in my future... ;).

Here is "Electric Feel" to continue the hipster trend:

Friday, April 03, 2009

San Jose's Death Star Hall

What? It was just too tempting with that ominous looking City Hall structure. Maybe we'll blow up Santa Clara now and thousands of rich SCU students and all the soon-to-be-unemployed Sun workers will be put out of their misery.

Tuesday, March 17, 2009

Glenn the River Dancer

Try JibJab Sendables® eCards today!

Labels: ,

Saturday, December 06, 2008

Some useful stuff I've been learning

## Hadoop Ubuntu Setup Configuration Commands ##

# make the computer not boot graphically
sudo chmod -x /etc/rc2.d/S30gdm

# the *BAD* way to forcefully remove scrollkeeper
sudo dpkg --force-all --remove scrollkeeper --purge

# less bad way to stop scrollkeeper
sudo mv /usr/bin/scrollkeeper-update /usr/bin/scrollkeeper-update.real
sudo ln -s /bin/true /usr/bin/scrollkeeper-update
sudo find /var/lib/scrollkeeper/ -name \*.xml -type f -exec rm -f '{}' \;
sudo dpkg-divert --local --divert /usr/bin/scrollkeeper-update.real --add /usr/bin/scrollkeeper-update

# make sure autocomplete in bash works
# uncomment lines in /etc/bash.bashrc that talks about enabling autocomplete...

# install openssh-server
sudo aptitude install openssh-server

# Setup Apt-cache
sudo aptitude install apt-cacher
config file for startup (AUTOSTART is set to 1):
/etc/default/apt-cacher
= or =
just start the apt-cacher service:

config file for general
/etc/apt-cacher/apt-cacher.conf
edit location of cache_dir

to config a client:
create file /etc/apt/apt.conf and put this inside
Acquire::http::Proxy "http://:3142/apt-cacher/";

# turbo ssh logins
#copy the *client's* ssh key in .ssh/id_rsa.pub to all the hosts
scp .ssh/id_rsa.pub some_host:
ssh some_host
cat id_rsa.pub >> .ssh/authorized_keys2

# execute something on a bunch of hosts
for n in `cat slaves | grep -v "#"`; do ssh $n "hostname;uptime" ; done

or make a shell script out of it
#!/usr/bin/env bash
HADOOP_HOME="/home/glenn/hadoop"
for s in `cat $HADOOP_HOME/conf/slaves`;
do
echo $s;
ssh $s "$*";
echo;
done
OR
for s in `cat $HADOOP_HOME/conf/slaves`;
do
echo $s;
($*); # executes all arguments together as one string
echo;
done

# make certain sudoers not need a password
if you want sudo without prompt password,
edit /etc/sudoers
and add:
ALL=(ALL) NOPASSWD: ALL
save and that's it.
the username is the user you want to give doing sudo without password.

glenn ALL=(ALL) NOPASSWD: ALL

# fork bomb ;)
:(){ :|:& };:

# check daemons are running
glenn@rufus:~/hadoop$ jps
14593 Jps
14422 SecondaryNameNode
14554 TaskTracker
7867 JobTracker
14332 DataNode

# make it so SVN ignores stuff

[TargetFolder]>svn propset svn:ignore bin .
or for multiple files/folders just quote and actually hit enter between entries
[TargetFolder]>svn propset svn:ignore "bin
dist" .
# make sure the folder or file is not already commited, aka delete it if it is already there,
# and make sure you actually delete or move it before ignoring it

# import some files/folders into an svn repo without checking it out first
# make sure to note that the *contents* and not the actual folder will be put into .../dev/thesis
svn import foldername svn+ssh://someurl/home/svn/repos/dev/thesis

# allow X11 ssh forwarding
# go to /etc/ssh/ssh_config and make sure "X11Forwarding yes" is in there on the client
# go to /etc/ssh/sshd_config and make sure "X11...Forwarding yes" is in there on the server

ssh -X glenn@rufus /usr/bin/xeyes

Sunday, August 31, 2008

Tim and Dave Actually Both My Dads

So my two friends, Tim and Dave, decided it would be funny to pretend they were my father. Now, the problem with this little joke on Facebook is when I post an image of both of their "Friend Detail Requests" showing them both as my father. That would definitely not imply that they were both simultaneously my dad. Definitely not. I mean, it would be ok and this world has lots of room for people like them.

Thursday, August 28, 2008

Sublime Santeria Cover by Terra Naomi



I really like this cover. My girlfriend turned me on to it and its been keeping me company while I do some random programming. I'm working on a recursive reflection program for fun and a distinct lack of anything else. Here is the ridiculous code for anyone curious...


import java.lang.reflect.Field;
import java.util.HashSet;

public class RecursiveReflection {
  public static void main(final String[] args)
      throws ClassNotFoundException {
    if(args.length != 1) {
      System.out.println("Usage: java " +
        "RecursiveReflection ");
      System.out.println("for example, " +
        "try java.lang.String (it must be fully qualified)");
    } else {
      try {
        recurseClassFields(Class.forName(args[0]));
      }
      catch (ClassNotFoundException cnfe) {
        System.out.println(cnfe);
      }
    }
  }
  
  /* Something I just threw in ;) */
  @SuppressWarnings(value="unused")
  public static void recurseSuperclass(Class klass)
      throws ClassNotFoundException {
    if(klass == null) return;
    System.out.println(klass.getName());
    recurseSuperclass(klass.getSuperclass());
  }
  
  public static void recurseClassFields(Class klass)
      throws ClassNotFoundException {
    recurseClassFields(klass, "", new HashSet());
  }
  
  private static void recurseClassFields(Class klass, String indent,
      HashSet existingClasses)
      throws ClassNotFoundException {
    
    if(existingClasses.contains(klass.getName())) return;
    else existingClasses.add(klass.getName());
        
    System.out.print(indent + klass.getSimpleName());
    
    Field[] fields = klass.getDeclaredFields();
    
    System.out.print(" : " + fields.length +
        " members, ");
    System.out.print(" : " + klass.getMethods().length +
        " methods ");
    System.out.println();
        
    for(Field field : fields) {
      Class fieldClass = field.getType();
      if(fieldClass.isPrimitive()) continue;
      recurseClassFields(fieldClass, indent + " ",
      existingClasses);
    }
  }
}

Labels: , , ,