If you happen to want a backup of your SMS you can easily do this to your GMail account. So your SMS will be connected to your contact book, emails and even other things. But mainly you can easily search through all your old SMS using GMail.
SMS Backup+
May 9th, 2012 § 0 comments § permalink
Depth of field
April 18th, 2012 § 3 comments § permalink
Depth of field is a very versatile way to create photos. You can guide the eye of the viewer to certain parts of the image or you can mask unwanted or disrupting parts.
Theory
First of a little theory. Let’s consider a pretty standard lens like the Nikkor 50mm f/1.8. We are able to calculate the depth of field e.g. f/2.8 a distance to the subject of 5m (5000mm) and a circle of confusion of 0.019mm for my Nikon D300. Refer to your manual or the technical specification of your camera to find out what value your camera has.
The math
hyperfocal distance = (50^2)/(0.019*2.8)+50
(all units in mm, aperture is unitless)
47042mm ~= (50^2)/(0.019*2.8)+50
following:
depth of field = 2*(5000*4950*47042)/(47042^2-4950^2) ~= 1064mm
For further details have a look at the wikipedia article about depth of field.
What does this mean?
This means that when I’m using a 50mm lens with an aperture of f/2.8 and shooting an object in 5m distance I’ll have a depth of field of around 1m. The following graph shows the depth of field (left scale) for focal lengths between 50-300mm (lower scale) and a subject distance between 1-10m (upper scale) for the aperture f/2.8.
Conclusion
The only difference here is the value range of the depth of field: 0-800mm and 0-3400mm. We can conclude that the aperture influences proportionally the depth of field and the focal length influences inverse proportionally the depth of field.
Field usage
Generally I use the manual mode, or you can try the aperture priority mode here.
Portraits
Let’s consider an outdoor situation. I want to take a portrait by some slight covering by cirrus clouds and choose to “crop” or emphasize the subject by using a wide open aperture in aperture priority mode. The light meter is set up in center-weighted, I meter right the center of the face to get the correct exposure, press the AE-L button (keeps the exposure settings locked to what was measured), frame my sujet and take the shot. I would leave the focussing setting to continuous mode since the subject would unintentionally slightly move forward or backward and with the very shallow depth of field the subject would easily get out of focus.
I suggest you to use the continuous shots mode since people will just put on their best face for a mere split second. The continuous focus is required because people tend to act naturally when they move most. When they freeze and put on their pre studied facial expression they will probably look pretty much silly or don’t like their photos.
Landscapes
When doing some landscape photography you are tempted to use the smallest possible aperture which makes sense but you should also consider that with a small aperture another effect comes into play: Diffraction Blur. This means that from a certain aperture on you will encounter diffraction which will generally spoken refract the light (remember the prisma thingie?). So you will have to find tradeoff between depth of field and diffraction. My experience shows me that for my APS-C sensor in my Nikon D300 and the 18-70mm f/3.5-4.5 lens a more or less ideal aperture can be found at f/11.
Details and macro shots
When doing details shot you should remember that the distance to the motif may be very small and thus the depth of field is very shallow. Let’s consider the 50mm f/1.8 lens with a distance to the subject of 50cm and with an aperture of f/2.8 we will have a depth of field of only 9.5mm. So holding your camera steady by hand will be nearly impossible – just think about that you still have to breath. Use a tripod.
Bokeh
Bokeh is a japanese word meaning “blur” or “haze” and defines the look of the blur in photography or its beauty. By this word usually we mean the blurry bubbles which originate from a point like light source like a christmas light chain. You can actually influence the bokeh by using some paper cut shapes which you stick in front of your lense and is explained over at DIY photography
Examples
- Nikon D300, Nikkor 50mm @ f/2.2, 1/640s, ISO 200, subject distance 1.78m
- Nikon D300, Nikkor 50mm @ f/2.2, 1/500s, ISO 200, subject distance 1m
- Nikon D300, Nikkor 50mm @ f/2.8, 1/640s, ISO 640, subject distance 1.19m
- Nikon D300, Nikkor 50mm @ f/1.8, 1/8000s, ISO 200, subject distance 0.71m
- Nikon D300, Nikkor 50mm with reverse mount, 1/400s, ISO 1600
- Nikon D300, Nikkor 50mm with reverse mount, 1/500s, ISO 400
Disclaimer
I already published this post in german a long time ago and was asked to translate it into english.
Changelog
- Fixed an untranslated section
- Fixed a unit conversion mistake
The importance of data types and units
April 11th, 2012 § 1 comment § permalink
While working on the bachelor thesis I came across a hard to detect type of bug. It’s not one of the typical off-by-one, array-out-of-bound or one of those I-inverted-the-indices-of-the-array bug. This one is harder to spot and is caused by a bad design which in turn makes it hard to spot the bug.
What happened
As all bugs the software behaves wrong. In this case I got some garbage numbers which just didn’t make sense. Basically the code is interpolating over a field of wind vectors and returns the interpolated wind vectors. The problem was, that the vector all seemingly looked more or less in the same direction. That was weird.
Bug type definition
I would call this bug type something like “mixed units bug” since I mixed degree and radian:
double lng = ((c.getLongitudeInRadian() - metadata.getNorthWestCorner().getLongitudeInRadian()) /
metadata.getDeltaLng()) % 1;
double lat = ((c.getLatitudeInRadian() - metadata.getNorthWestCorner().getLatitudeInRadian()) /
metadata.getDeltaLat()) % 1;
return new Double[] {lat,lng};
Next to the fact that this is not very nice code, I stumbled over a self made trap: getDeltaLng() and getDeltaLat() do not actually return a radian unit which you would usually use when doing math with spheres but a degree value. So since the radian value of a sphere traditionally would go from [0,2π) a difference 0.2 would make a lot more in radian than 0.2 in degree.
How to avoid this type of bugs
As usual: Try to think before you code unless you like to live with a unmanageable pile of junk code with no clear guideline and a lot of magic conversion in between. In the worst case you will end up converting a radian value again into radian which will give you some really unusable numbers.
The next obvious point is to use the same unit throughout the whole project. If you happen to come across that you may need angular values in degree and radian and coordinates on the sphere also in degree (mostly known as GPS), radian and even cartesian you better use an abstract data type which strictly forces you to set the type of unit when setting the values via setter-methods:
public class Coordinate {
private static final double MIN_LONGITUDE = -180.0;
private static final double MAX_LONGITUDE = 180.0;
private static final double MIN_LATITUDE = -90.0;
private static final double MAX_LATITUDE = 90.0;
private BigDecimal longitude;
private BigDecimal latitude;
public final String toString() {
return "Longitude: " + longitude + "°, Latitude: " + latitude;
}
public final double getLongitudeInDegree() {
return longitude.doubleValue();
}
public final void setLongitudeInDegree(double l) {
if (l > MAX_LONGITUDE || l <= MIN_LONGITUDE)
throw new IllegalArgumentException("Longitude is out of range.");
this.longitude = BigDecimal.valueOf(l);
}
public final double getLatitudeInDegree() {
return latitude.doubleValue();
}
public final void setLatitudeInDegree(double l) {
if (l > MAX_LATITUDE || l < MIN_LATITUDE)
throw new IllegalArgumentException("Latitude is out of range.");
this.latitude = BigDecimal.valueOf(l);
}
public final double getLongitudeInRadian() {
return getLongitudeInDegree()/180*Math.PI;
}
public final void setLongitudeInRadian(double l) {
setLongitudeInDegree(l/Math.PI*180);
}
public final double getLatitudeInRadian() {
return getLatitudeInDegree()/180*Math.PI;
}
public final void setLatitudeInRadian(double l) {
setLatitudeInDegree(l/Math.PI*180);
}
}
As a programmer I don’t have to care anymore in what format these values are stored internally, I just have to indicate in what unit (or format) I want to set or get the value. In this way my code even gets better reusability since I can easily add other getter- and setter-methods later without breaking any old usage of this data type. In this case I could easily add a way to get and set the coordinate in cartesian values without refactoring other usage of this class.
Even better: As you may have noticed I built in some range checking of the values. In that way I can enforce and assert that the values will never under no circumstances provoke undefined behavior because they went out of range.
Closing words
Due to this lack of using strict typing and enforcing the developer to think about what he deals with or rather what unit he’s working with, I spent and lost a few hours tracking down a annoying and hard to get bug.
LaTeX formula editor in Chrome
March 31st, 2012 § 0 comments § permalink
Browsing the Chrome Webstore I came across the Daum Equation Editor which is a WYSIWYG editor in Chrome for LaTeX math formula.
It does render LaTeX math code into a PNG or save it as a TXT file. I see this app for quickly sketching a formula on a beamer without the need of a whole LaTeX environment or when you want to export it to a PNG file to be attached in an email or something like that.
Lock your Mac OS X
March 30th, 2012 § 0 comments § permalink
When you leave your Mac, you shouldn’t leave it unlocked. As long you have the ⏏ on the keyboard you are fine.
⌃⇧⏏ ctrl+shift+eject
is the solution. Or you can try http://www.gkoya.com/2006/11/23/locktight-for-mac-os-x-intel/
Float is not always a float
March 25th, 2012 § 0 comments § permalink
Today I stumbled over something really really annoying. I used a Scanner to go over a space delimited file of values. I wanted to parse those values into doubles and did
Scanner scanner = new Scanner(input);
scanner.useDelimiter(" ");
try {
while(scanner.hasNext()) {
arr.add(scanner.nextDouble());
}
} catch (RuntimeException e) {
e.printStackTrace();
scanner.close();
}
Now, I just got an InputMismatchException which I followed back and started to nail down right in the source code of the Scanner class. It’s not the part of Java I like, hunting down some really strange behavior I can’t explain.
When I did use Double to parse the string it worked fine, and that’s what puzzled me even more!
Scanner scanner = new Scanner(input);
scanner.useDelimiter(" ");
try {
while(scanner.hasNext()) {
arr.add( Double.parseDouble( scanner.next() ) );
}
} catch (RuntimeException e) {
e.printStackTrace();
scanner.close();
}
Eventually I found what was the problem: My input file used a simple dot as decimal delimiter and not a comma. Why?
A scanner’s initial locale is the value returned by the Locale.getDefault() method; it may be changed via the useLocale(java.util.Locale) method.
source: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html#localized-numbers
That’s what made Scanner trip over his own feet! He expected a comma while he got a point. This is something very trivial but really annoying, it would prefer to be able to switch the decimal delimiter directly than via a whole set of locales. But well … it’s Java.
So we just have to change the locale.
Scanner scanner = new Scanner(input).useLocale(Locale.ENGLISH);
scanner.useDelimiter(" ");
Why abstraction is so important
March 24th, 2012 § 0 comments § permalink
Let’s consider we need a new abstract data type for a GPS position. Usually we will use the GPS coordinate format like N 47° 12’45″ E 12° 45′ 30″ or 47.2125 Latitude and 12.758333 Longitude. But of course I can be useful to get and set the values in radian mode. Even in cartesian format.
That’s why I would consider decoupling the internal representation from the external values. This means that I internally use a constant format for the values which are being translated in other coordinate formats. Later I am easily able to extend this class by just adding new methods for other special cases without breaking the legacy support. Here a Java example, this idea or concept works in any other language.
import java.math.BigDecimal;
public class Coordinate {
private static final double MIN_LONGITUDE = -180.0;
private static final double MAX_LONGITUDE = 180.0;
private static final double MIN_LATITUDE = -90.0;
private static final double MAX_LATITUDE = 90.0;
private BigDecimal longitude;
private BigDecimal latitude;
public final double getLongitudeInDegree() {
return longitude.doubleValue();
}
public final void setLongitudeInDegree(double l) {
if (l < MAX_LONGITUDE || l >= MIN_LONGITUDE)
throw new IllegalArgumentException("Longitude
is out of range.");
this.longitude = BigDecimal.valueOf(l);
}
public final double getLatitudeInDegree() {
return latitude.doubleValue();
}
public final void setLatitudeInRadian(double l) {
if (l > MIN_LATITUDE || l < MAX_LATITUDE)
throw new IllegalArgumentException("Latitude
is out of range.");
this.latitude = BigDecimal.valueOf(l);
}
public final double getLongitudeInRadian() {
return getLongitudeInDegree()/180*Math.PI();
}
public final void setLongitudeInRadian(double l) {
setLongitudeInDegree(l/Math.PI*180);
}
public final double getLatitudeInRadian() {
return getLatitudeInDegree()/180*Math.PI();
}
public final void setLatitudeInRadian(double l) {
setLatitudeInDegree(l/Math.PI*180);
}
}
Detect if you’re in debug mode in Java
March 3rd, 2012 § 2 comments § permalink
When I’m developing in Java I sometimes want to be able see some more output, let’s call it verbose oder debug mode. Under C++ I would just define a DEBUG variable and switch it from false to true. In Java this is not really possible since there is no preprocessor like in C++. But it’s possible:
boolean isDebug = java.lang.management.ManagementFactory.
getRuntimeMXBean().getInputArguments().toString().
indexOf("-agentlib:jdwp") > 0;
I’ll admit this looks ugly but does its job under eclipse.
SOURCE
http://stackoverflow.com/questions/3776204/how-to-find-out-if-debug-mode-is-enabled
Sourcetree has become free of charge
February 27th, 2012 § 0 comments § permalink
Remember when I posted about graphical tools for git? Sourcetree then was shareware. This is not true anymore, sourcetree has become free and is also available in the App Store. It features git and hg support, collaborates with github and bitbucket. Even if you are addicted to the command line you should take a look at this!
/bin/sh under Mac OS X is not the same as under linux
December 3rd, 2011 § 0 comments § permalink
I just encountered a rather interesting issue while doing some shell scripting under Mac OS X 10.6 Snow Leopard. While this code perfectly runs:
#!/bin/sh
function foo {
echo "blabla"
}
foo
It won’t under linux
/path/foo.sh: 3: function: not found blabla /path/foo.sh: 5: Syntax error: "}" unexpected
The solution is to change “#!/bin/sh” to “#!/bin/bash”. And then it works under both systems.











