A shout out to the ImagePaste WordPress Plugin

The ImagePaste plugin is a great timesaver if you are blogging screenshots.  It copies images from your clipboard and uploads it to the server automatically.

I usually use the Windows Snipping Tool to capture my screenshots

In the past, I’d have to save this to a file and then upload to the server. Now, with ImagePaste, it’s a matter of CTRL+V into the mce text area.

NB:

  1. The presence of JetPack interferes with ImagePaste.
  2. You need to be in Visual Mode for ImagePaste to work.

How to create a JavaFX control from scratch

Thanks to Richard Bair

  1. Extend Control class,
  2. Set the Stylesheet,
  3. Provide no arg-constructor
    public class MoneyField extends Control {
        /**
         * Creates a new MoneyField. The style class is set to "money-field".
         */
        public MoneyField() {
            getStyleClass().setAll("money-field");
        }
     
        @Override protected String getUserAgentStylesheet() {
            return getClass().getResource("MoneyField.css").toExternalForm();
        }
    }
    
  4. Create .css file in the same package
  5. Define .money-field class (see how constructor sets style to “money-field”)
  6. Define -fx-skin: “fully-qualified-name-of-ControlSkin”;
  7. Create Skin class
    public class MoneyFieldSkin implements Skin<moneyfield> {
    }
    

  8. In constructor, create the controls required for the shadow-DOM
    public class MoneyFieldSkin implements Skin<moneyfield> {
        /**
         * Create a new MoneyFieldSkin.
         * @param control The MoneyField
         */
        public MoneyFieldSkin(final MoneyField control) {
            this.control = control;
     
            // Create the TextField that we are going to use to represent this MoneyFieldSkin.
            // The textField restricts input so that only valid digits that contribute to the
            // Money can be input.
            textField = new TextField() { // ...
            };
     
            // ... and a lot more stuff!
        }
    }
    

Continue reading

On Ubuntu’s new smartphone OS

BBC reports:

The Ubuntu operating system has been adapted to run on smartphones.

The Linux-based software will allow users to run desktop apps on their handsets, allowing them to double for PCs when docked to monitors.

Here are the reasons why I think Mark Shuttleworth is doing this:

Today, Linux is everywhere in the sense that beneath Android – runs Linux. Unfortunately, Ubuntu doesn’t figure in the equation. Tablets, phones are all locked down devices and enthusiast/hobbyist open source doesn’t figure unless drivers are available. To maintain relevance, Ubuntu needs to exist in the mobile space.

Today’s announcement is an early one, and is making the same value proposition as Android did early on, before Google’s acquisition. i.e. an open source system that any phone vendor can use to build their smartphone platforms on.

The Problems

Ubuntu has a remarkably polished desktop product for years but it has remained a fringe product and the PC market has simply stopped growing. Jobs has carefully taken Apple around MS’s hegemony on the desktop by tackling music players first, then a pincer movement through Windows Mobile dominance by producing a very expensive smartphone.

Shuttleworth faces not one but several well established and cashed up competitors – Apple, Google/Samsung, Amazon. I haven’t even mentioned Microsoft, or the Chinese Korean and Taiwanese versions of a smartphone OS. Each of them have an arsenal of patents and services that gives them degrees of freedom to move around the space. Google for example commands the email/contacts/calendar integration, YouTube, Maps and Navigation. Google’s approach is to deny competitors full functionality of these services to cripple their smartphone offerings. e.g. turn by turn in the case of iOS, YouTube search APIs in the case of Windows Phones. Apple and Amazon have offered cloud locker services for those who purchased music and books from their online stores. Microsoft has some cards left in enterprise management and server integration.

Next steps

I believe this is just an initial salvo. Promising compatibility with Android kernel level drivers is a good start. Right now there isn’t enough value proposition for Ubuntu phone in terms of apps or services. Integrating a phone and desktop are novel but it is far from a sure bet. A reference phone design might be good bet if they think it will persuade some of the smaller Chinese manufacturers to jump onboard. However, this will not please Dell. It might make a MIUI-like play, and remain a niche phone OS for several years until the opportunity is right.

What Ubuntu really needs to do now as an organisation is to make a sideways bet into iOS and Android. It needs to kick start development of its own mail app, or acquire a navigation maker like Waze, and get these loaded onto the popular phones today. There is still some geek-cred left in Ubuntu for people to load these apps on, and who knows, they might catch on in the enterprise space.

Getting the Assembly’s Version Number and Public Key Token from the command line

Here’s a compiled binary from Scott Hanselman’s site: http://www.hanselman.com/blog/OutputAnAssemblyVersionFullyQualifiedNameFromTheCommandLine.aspx

Example:

\bin\AssemblyVersion.exe System.Data.SqlServerCe.dll
System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91

Download here (.NET Framework 2.0):
AssemblyVersion.exe

T-SQL when SQL Server Management Studio is not available

C:\Program Files\Microsoft SQL Server\100\Tools>sqlcmd -S .\SQLEXPRESS

1> — Fetches the logical names from a backup file
2> RESTORE FILELISTONLY FROM DISK=’C:\VMS\2mtsam_com.bak’
3> GO

1> — Restore the back up file
2> RESTORE DATABASE SAMDB FROM DISK=’C:\VMs\2MTSAM_COM.BAK’
3> WITH
4> MOVE ‘SAMDB’ TO ‘C:\VMs\SAMDB.mdf’,
5> MOVE ‘SAMDB_LOG’ TO ‘C:\VMs\SAMDB.ldf’
6> GO

C:\Program Files\Microsoft SQL Server\100\Tools>sqlcmd -S .\SQLEXPRESS
1> create login SamDbUser with password=’SamDbUser’
2> go
1> use samdb
2> go
Changed database context to ‘SamDb’.
1> create user SamDbUser FROM LOGIN SamDbUser
2> GO
1> sp_addrolemember ‘db_owner’, ‘SamDbUser’
2> GO

with thanks to StackOverflow

Reference:
Create User TSQL
TSQL Map User To Database

Seagate Momentus XT 500 GB benchmark

Seagate Momentus XT

As the figure above shows, 105 Mb/s isn’t particularly outstanding. Here’s a site giving HDD speed benchmarks.

Hitachi Ultrastar 15K450 SAS 450GB – 95.8 – 154.1 – 132.2 repman244
Western Digital 06000 600GB – 84.8 – 139.1 – 118.0 rfowler30
SAMSUNG Spinpoint F3 2TB – 67.0 – 147.7 – 116.3 Me
Western Digital Green WD20EARS 2TB – 66.3 – 147.7 – 114.4 Silkstone
Samsung HD502HJ – 68.6 – 139.0 – 111.5 0x0000007b
Samsung Spinpoint F3 500GB – 55.4 – 146.6 – 111.5 Jetster
Western Digital Black 640GB – 78.5 – 136.4 – 111.2 LifeOnMars
Western Digital Caviar Black 2TB – 9.7 – 142.5 – 111.0 arnoo1
Seagate Barracuda Green 2TB – 59.0 – 147.6 – 109.7 – repman244
Samsung F3 2TB – 18.2 – 126.9 -108.4 JATownes
Samsung EcoGreen F4 2TB – 63.3 – 142.0 – 108.3 Jetster
Seagate Barracuda 7200.12 500GB – 51.3 – 134.0 – 105.1 stefanels
ST3205318AS 250GB – 65.8 – 127.5 – 105.0 Romeopp
Toshiba MBD2147RC SAS-2 (6 GB/s) 146GB – 74.4 – 127.3 – 103.9 repman244
SAMSUNG HD502HJ 500GB – 5.2 – 134.4 – 103.5 Silkstone
Western Digital Black 500GB Sata 3 – 62.9 – 138.1 – 102.4 james888
Western Digital WD5000 500GB – 58.1 – 126.8 – 101.5 Specks
Western Digital WD5000 500GB – 57.1 – 118.6 – 95.7 Romeopp
Seagate Momentus XT 750GB – 57.2 – 122.1 – 94.8 VulkanBros
1 TB Spinpoint F3 – 52.5 – 116.5 – 93.0 HTC
Seagate 1TB – 2.8 – 117.1 – 90.6 JATownes
Seagate 500 GB Momentus XT ST95005620AS – 19.6 – 109.5 – 83.2 (On Dell Vostro laptop)
Seagate 320GB SATA – 82.1 bogmali
Western Digital WD2500 250GB – 49.1 – 101.6 – 81.7 Silkstone
Toshiba 500GB 7200rpm – 44.5 – 98.7 – 75.1 repman244
Western Digital Green Cav. 500GB – 43.0 – 91.3 – 72.8 de.das.dude
Seagate Barracuda 7200.10 250GB – 54.1 – 81.2 – 70.0 – repman244
Toshiba MK3265 320GB – 43.5 – 88.0 – 67.8 Derek12
Seagate ST3320620AS 320GB – 39.4 – 69.7 – 61.8 bogmali
Western Digital Scorpio Blue 250GB – 37.7 – 65.9 – 51.8 – Derek12
P4 Northwood PATA 160GB – 25.0 – 55.5 – 43.8 Completely Bonkers (LOL)

Hardened Stateless Session Cookies – Murdoch

Reference - http://www.cl.cam.ac.uk/~sjm217/papers/protocols08cookies.pdf

Summary of key points

Stateless session cookies refer to the fact that there is no state stored on the server-side. i.e. instead of a session cookie id fe00adecafebad being paired with some server state, eg. username, the user name is stored in the cookie itself.

Before you think this is a hare-brained idea, Murdoch has a scheme to secure this.

  1. Account Creation – Use repeated hashing so that passwords are expensive to brute force. The number of iterations can be increased if CPU power increases. e.g. bcrypt. For the purposes of illustration, we will hash 256 rounds.
  2. Upon authentication, use the following session cookie format:
    • Expiry date/time
    • Secured data – e.g. username
    • Authenticator – (salt + password) hashed to 255 rounds
    • Digest e.g. HMAC-SHA-256 of [machine secret + expiry date/time + secured data + authenticator]

This scheme is protected by several secrets

  1. A password
  2. A cryptographically long salt
  3. A machine key MAC

An expiry date protects the cookie against long term reuse.

The authenticator in the session is no use to the attacker without a salt. (However, rainbow tables might be useful here).

The machine key can be rotated regularly if salt and hashed password are leaked.

git primer

So you’ve installed git on Windows, now what?

Firstly, set up your credentials and basic preferences. GitHub setup guide is a good reference. All you actually need for now is listed below.

Since we will be working with Windows exclusively, we do not care about keeping line endings unix compatible, nor do we care about filemodes.

git config --global user.name "Billy Everyteen"
git config --global user.email "Billy.Everyteen@mac.com"
git config --global core.autocrlf false
git config --gloabl core.fileMode false

Next, clone a repository. Launch GIT GUI and enter a repository URL, and the local checkout directory. (You may be prompted for a username and password if the repository is secured).

Alternatively, if you are more comfortable with the command line, launch git bash:

$ cd "C:\Users\Chui\Projects"
$ git clone http://xyz.com/xyz/xyz.git

Tip

You can save the username password in a .netrc file.
See Use netrc on Windows

Customizing configuration files

Next, identify all the files that are not to be checked into the project. In my projects, I usually name them xyz.sample.ext. Make a copy of the file with the .sample. omitted. If these are configuration files, the contents need to be adjusted for database connection strings, SMTP server strings etc.

Ignoring changes

In some cases, if you need to make changes to files that shouldn’t be committed to the source control, you may do the following:

# StarterSite.sdf is a database file. Ignore any changes to this file.
$ git update-index --assume-unchanged App_Data\StarterSite.sdf

Using .gitignore to ignore files

.gitignore can also be used to ignore files. This is only good for files haven’t been checked in before. Once a file has been checked in, .gitignore no longer works.

Making source changes

I recommend the following approach: declare what you wish to change before making any changes. This way, you won’t end up with a bunch of modified files for different issues.

When you’re done with changes, hit the “Rescan” button. That’ll bring up all the changes you’ve made. Then, select each file that should be checked in, and type CTRL+T to “stage” them. (git operates on a two-phase commit system, you stage the changes and then commit them in a single swoop).

Pushing your changes to a central repository

When you make a code commit, the changes are committed to the .git subdirectory. This is a full .git repository with a history of all commits. “Pushing” your changes pushes the incremental changes back to the origin server where you cloned the repository.

This can be done from GIT GUI or from the command line

# Note: master is roughly the equivalent of the "trunk" branch in svn
$ git push origin master

Pushing your changes to a shared central repository (i.e. multiuser)

If there are multiple people pushing to the same central repository, then you will be required to pull the repositories changes before pushing them.

# saves modified files from the working directory to a stash area, reverts files
$ git stash save

# gets latest changes
$ git pull origin master

# At the stage conflicts may occur. See dealing with conflicts.

# retrieves files back into working directory
$ git stash pop

# push changes
$ git push origin master

Dealing with conflicts

The conflicts may appear cryptic but is rather straightforward. See merging conflicts with git

Testing Multitouch Windows without an x86 tablet

Touch-based devices are everywhere except Windows. Most people I know own an iPad or an Android tablet. But a touch-enabled Windows PC is still a relative rarity.

The Splashtop Remote Desktop App for Android and the associated Windows 8 streamer transmits touch events to the PC from the tablet, and I found it makes a pretty reasonable environment for developing touch enabled apps.

Personally, I’m interested in this if it gives Silverlight some measure of longevity. After all, there are a lot of enterprise software already built with Silverlight, and if one could sprinkle pixie dust to make it touch-friendly, why would one redevelop it in Metro Windows Runtime?

Here are some demos you can try:

  1. Multitouch Demo Silverlight Article
  2. Landsat Touch ESRI Silverlight Article
  3. Multitouch Slide View Article Silverlight
  4. JavaFX Multitouch (Netbeans required) Tutorial – if there’s enough interest I’ll work out how to embed this as an applet.

Splashtop works well. There is of course some lag in the video, but it is a cheap way to test touch on Windows until a suitable tablet comes along. There is one gripe. Splashtop alters the screen resolution of the PC to match that of the device. For touch applications, this can play havoc with the size of the touch targets. In addition, the resolution of my android tablet doesn’t even meet the minimum resolution required for Metro WinRT applications.