Test your CPU for 32 or 64 bits with gcc

Here’s an easy way to tell if your processor is 32 or 64 bits.  The __WORDSIZE def in glibc is either 32 or 64 bits, and here’s how you check it:

You can just type ‘make’ and then run the test program that is generated.  Here is a zip file with the code above and a Makefile: cpu-test

If you don’t want to use the Makefile, just do:

make && ./test

 

So:

[mike.baranski@switters cpu-test]$ ls
Makefile test.c
[mike.baranski@switters cpu-test]$ make
gcc -o test test.c
[mike.baranski@switters cpu-test]$ ./test
32
[mike.baranski@switters cpu-test]$

JQuery how to resize table and keep table size

When removing a table row, you can prevent an html table size from changing by setting the width explicitly before removing the row:


 

Javascript function application / currying / callbacks

Javascript partial functions:Here, doSomething is a callback and the second argument should be data from a JQuery ajax call.Say you have a function:


There can be any number of arguments after passing in the function argument, like: partial(fn, arg1, arg2, …, argn), these arguments are applied to the function you will be calling.


 

The callback after the post will behave just like you called: doSomething(“Test Value”, data) where data is the $.post result.

 

Postgres on Openshift Java Application

Using an openshift JBoss/Postgres setup trying to create a webapp with a postgres database.

Turns out that the openshift ${OPENSHIFT_POSTGRESQL_DB_URL} variable does not work with the postgres 9.2 JDBC driver.

It’s broken.

The URL should be: jdbc:postgres://hostname:port/database. The URL provided by openshift is not that format.

Note also that SSL is not supported by the database server.

Here is the properties placeholder I’m using with Spring.

driver_class=org.postgresql.Driver
url=jdbc:postgresql://x.y.z.a:5432/
username=nottherealusername
password=thepasswordforpgsql

I know that the system creates a JNDI connection, but my maven build copies a properties file if the Openshift profile is run, and copies a different properties file if it’s building locally. This allows the proper database connection to be made depending on where it is built.

Java MD5 with no external dependencies

How to generate an MD5 sum with Java – no external dependencies.

To run the file, do:

javac T.java && java T

Or
javac T.java
java T

 

SQL Server int datetime rounding errors

Demonstration of errors when casting between float and datetime in SQL Server.

 

SQL Cast Example Data

Synchronous JavaScript for image validation

This function will return an image link if the url passed in is valid, otherwise it will return the no-image text. This is synchronous ajax, which will block your UI, but I use it for popover generation with bootstrap js, and it works just fine.