Short source code examples

Nothing major to see here, but some Linux xscreensaver commands I don’t want to forget:

# download an xscreensaver package
$ sudo apt-get install xscreensaver-data-extra

# restart xscreensaver
$ pkill xscreensaver && xscreensaver -nosplash &

This example shows how to URL-encode HTTP query parameters using Ext.urlEncode in a Sencha ExtJS (or Touch) application:

Here is a small collection of Sencha ExtJS ‘Store’ objects from a recent project. I suspect they will also work with Sencha Touch, though I haven’t tried them there yet. (They may need a few small modifications, dunno.) I share them here hoping they will help anyone who needs to see some =Store= examples.

First, this Store object is named Users:

As a quick example of how to loop over each element in a Sencha Touch or ExtJS store, I use the following code to dynamically create a series of checkboxes.

In short, in a Sencha controller:

Ext.define('Focus.controller.Projects', {
    extend: 'Ext.app.Controller',

I declare a Store:

stores: [
    'Tasks'
],

then later create a reference to the Store:

This source code shows how to use the Sencha Touch Ext.XTemplate:

There are times when working with Sencha Touch where I try to make things too hard some times, but in this case, I’m pretty sure this is the simplest possible Sencha Panel with embedded HTML:

var myPanel = Ext.create('Ext.Panel', {
    html: 'Hello, world'
});

I don’t think it can get any easier than that.

The following Python example shows how to split a string into a list, get the second element from the list (which happens to be a long), and convert that string to a long value:

line = 'Foo bar baz|1234567890'
ts = line.split('|', 1)[1]
t = long(ts)

I needed to do this for my Radio Pi project, and this code worked out well.

Here’s an example of how to print the formatted time in Python:

import time
print time.strftime("%a, %b %d %I:%M %p")

That code results in the following output:

Thu, May 29 11:26 AM

To see what’s running on a Mac OS X port, use this lsof command:

$ sudo lsof -i :5150

This command shows what’s running on port 5150. Just change that to whatever port you want to see.

To build a Sencha ExtJS application, move to your project’s root directory, then run this command:

$ sencha app build

Assuming that the build works fine, you can test the production build in your browser at a URL like this:

I just tried a quick test of transparency/translucency on Mac OS X using Java, and in short, here is the source code I used to create a transparent/translucent Java JFrame on Mac OS X 10.9:

Here are a few examples of how to set the Font on Java Swing components, including JTextArea, JLabel, and JList:

// jtextarea
textArea.setFont(new Font("Monaco", Font.PLAIN, 20));

// jlabel
label.setFont(new Font("Helvetica Neue", Font.PLAIN, 14));

// jlist
list.setFont(new Font("Helvetica Neue", Font.PLAIN, 12));

A test application

You can use code like the following Scala code to easily test different fonts. Modify however you need to, but it displays a JFrame with a JTextArea, and you can change the font on it:

If you want the horizontal and/or vertical scrollbars to always show on a Java JScrollPane, configure them like this:

scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

Other options are:

HORIZONTAL_SCROLLBAR_AS_NEEDED
HORIZONTAL_SCROLLBAR_NEVER

and:

I just learned how to send STDOUT and STDERR to a file in a Java application (without using Unix shell redirect symbols). Just add these two lines of code to the main method in your Java (or Scala) program:

System.setOut(new PrintStream("/Users/al/Projects/Sarah2/std.out"));
System.setErr(new PrintStream("/Users/al/Projects/Sarah2/std.err"));

Then when you use:

System.out.println("foo");

or

Nothing major here, I just wanted to note the use of several scalacOptions in the following build.sbt example:

Here’s a quick example of how to use a Sencha ExtJS or Touch DelayedTask:

onMainViewportAfterRender: function(viewport, options) {
    var tabPanel = viewport.down('tabpanel');
    var task = new Ext.util.DelayedTask(function() {
        tabPanel.setActiveTab(0);
    });
    task.delay(250);
}

As shown, the first thing you do is create a task by giving a DelayedTask a callback function. Then you tell the task how long it should delay before executing.

As a quick note today, here are my current Sencha utilities (most of them being string utilities):

I learned today that you break out of a Sencha ExtJS Store each loop by returning false from your function. This code shows the technique:

Sencha ExtJS - How to dynamically create a form textfield (Ext.form.field.Text)

Without much introduction, here’s a large block of Sencha ExtJS controller code. The code needs to be cleaned up, but at the moment it shows:

The following code shows how to dynamically create a Sencha ExtJS form textfield, i.e., a Ext.form.field.Text field. Maybe one of the best things about this example is that it shows how to get input focus on a textfield: