About jontas

I like to make things that people find useful.

(JQuery) Uncaught TypeError: Property ‘$’ of object [object someObject] is not a function

This can happen for instance when JQuery has not been fully loaded before trying to execute JQuery code.
Using $(document).ready(function($) is one way to solve this, as this should wait until JQuery is fully loaded.

<script type="text/javascript">
  $(document).ready(function($) {
    //some awsome jquery code
  });
</script>

Python: Converting from string to integer/float

myString = "545.2222"
float(myString) #545.2222
 
#or to round it of
int(float(myString)) #545
 
#or to keep us safe in case the myString should be checked for "funny" values
try:
    i = int(myString)
except ValueError:
    i = 0

Specifying the JVM to run Eclipse with

Specifying the JVM Eclipse should use is both a nice way to make sure it is correct now and to know that future upgrades/updates won’t mess with this.

This is done by specifying the -vm option in the “eclipse.ini” file.

Important bits to know about this:

  • -vm option and the path must not be on the same line
  • You should give the Java excecutable here, not just the path where is is located
  • if you also have -vmargs the -vm must be before that in the ini file

Example eclipse.ini (for windows)

-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vm
C:\progra~1\Java\jdk1.6.0_26\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m

pretotyping vs productyping

Something to keep in mind when starting the adventures of rapid prototyping (and 3D printing) – or for that matter during software development, is to consider what we need to create and do just that.
Pretotyping is about “Make sure you are building the right it before you built it right.”
A prototype is made to make sure we are building it right, but too seldom a pretotype is created to test that the right it is being built.

So the great idea with a pretotype is about failing early (with low costs) or starting making a prototype of the important bits.
The good thing with failing early is of course that we can move on to the next idea and sooner find the ideas that are worth developing.

A productype on the other hand is the opposite, when features are added before the need for them is identified. The following two comics from “Rep rap adventures” and “xkcd” both show the problem with launching too late (or productyping; witch is when features not realy needed are added), and this is part of why a pretotype is nice. The sooner we can find the right it (and that is what pretotying is about) the sooner we can make a prototype and get to the market sooner.

rep rap adventures

xkcd

So why should we preotype, can’t we just make a cheep protoype?

Based on my dayjob at wi.se I have drawn the conclusion that the pretotype should be used to find the right it, not a argument for making a cheaper prototype. Even if you get someone (like us) to do a prototype for you for free – that will not help at all if it is not for the right it. Also in a pretotype it is more common (and accepted, even liked) to cheat/pretend that functions are working or simply faking them, in a prototype more often features are there, but might be limited in function.

svn switch

To change the branch you have checked out you use “svn switch url [PATH]” (the path is optional).
example:

svn switch https://example.com/svn/root/branches/thebranch .

Also svn switch can be used to “relocate” the repository url – i.e. if the server has moved/changed address/ip or similar. “svn switch –relocate FROM TO [PATH]”
example:

svn switch --relocate https://old.example.com/svn/root/oldbranch https://new.example.com/svn/root/newbranch .

warning: Only if the working copy still reflects the same repository directory, but the location of the repository itself has changed, then svn switch –relocate is safe to use.

Java PostgreSQL timestamp to a Unix timestamp

Suppose we have a timestamp in the database and would like to convert it to a Unix timestamp
There is a function called getTime() that will return the unix time.

long messageTime = rs.getTimestamp("startTime", Calendar.getInstance(TimeZone.getTimeZone("UTC"))).getTime();

PostgreSQL getting the lastest item from a history table (the entry with the latest timestamp)

SELECT * FROM history_items
WHERE timeofhistory=(SELECT MAX(timeofhistory) FROM history_items)

The sub query will fetch the highest timestamp and then that is used as a condition for the query.

note: If you are using a version older than 8.1, then MIN and MAX is not able to use indexes, so instead use a ORDER BY and LIMIT clause

SELECT * FROM history_items
ORDER BY timeofhistory DESC LIMIT 1

This will of course work for versions 8.1 and higher as well, it should be identical to MAX and MIN in time.