To install the mysql gem for Ruby 1.9.1 on Ubuntu Lucid, you need the headers so that it gets compiled properly. What I did to install it was:
sudo apt-get install libmysqlclient15-dev sudo gem install mysql
To install the mysql gem for Ruby 1.9.1 on Ubuntu Lucid, you need the headers so that it gets compiled properly. What I did to install it was:
sudo apt-get install libmysqlclient15-dev sudo gem install mysql
As you probably know, when shooting landscape, there are two “magic” times: dawn, about 30 min before sunrise, till 30 min after, and dusk. According to Scott Kelby, some magazines do not even consider looking at pictures if they are not taken at either of these 2 times. So this morning I got up at 5 am (something I don’t remember doing willingly in yonks), and headed to Greystones beach. Not that I intend to publish pictures or anything, but I do want nice pictures.
I. Loved. it. Every second of it. The sunrise was amazing, the birds flying around was a real pleasure, the village looked peaceful in the distance, the sea was quite soothing (had I needed soothing at 6 in the morning…), and no one about. Cleared my head, put a big smile on my face, and at first glance, there are one or two focusandshootable pictures in the lot…
The new tripod is awesome. It is very light and though it can sometimes be a bit of a problem, it wasn’t this morning: no wind at all, and I certainly enjoyed its lightness (and its bag) whilst walking around. I used bracketing a bit, but having looked at the result, it appears the correctly exposed picture is the keeper.
Now in the future, I’ll probably have to be a bit more organized: I was lucky enough to wear a coat with large pockets, handy enough to put stuff like lens caps, but dropping a lens in the sand because I forgot to close my camera bag was rather high on the scale of idiocy… Also, I didn’t realise the camera was set to ISO 400, which I’m a bit annoyed about: a bit of a bummer if you use a tripod.
Comme c’est un mot à la mode, je ne résiste pas au plaisir de partager avec vous sa définition :
Une palinodie (du grec πάλιν (palin), de nouveau, et ὠδή (ôdê), chant) est un texte dans lequel on contredit ce que l’on avait affirmé auparavant.
PHP recently stopped interpreting PHP scripts in public_html after a (Lucid) Ubuntu update: instead of displaying the generated HTML, it was just offering to download the script — the kind of “new” behaviour that leaves you baffled for a few minutes…
After reinstalling apache and PHP without any luck, I looked into Apache configuration, and in the PHP5 mod, here is what I found:
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
The PHP engine is explicitly disabled in public_html, yes sir. Comment out the bit above using hashes, restart your Apache server (sudo service apache2 force-reload), and you’re sorted.
Not sure why this change has been made, though.
So birds prefer nesting in As and Rs.
If you were walking your dog, or running on Dun Laoghaire pier last night, you may have seen a group of weirdos walking around with their tripod and camera, and waiting for a long time to get the right shot. Well, that was us.
It has been really fun, I must admit, and I’ve learnt quite a fair bit. I’m still really frustrated with my camera and my own skills; but I feel I’m getting somewhere. Now it is time to practice even more, and I guess I’ll keep an eye out for a photography club or something in Wickla!
If you’re interested in the results of the shoot, I have posted a few pictures on focusandshoot.net, so they’ll be appearing in the next couple of weeks: stay tuned!
After long hours of hair pulling, I gave my little Spring MVC app a go in a different app server (namely, GlassFish), and realised that my Expression Language expressions were working just fine there, whereas they were not getting evaluated at all in Google apps.
Well, turns out, that’s known issue. Just add:
<%@page isELIgnored="false"%>
at the top of your JSP, and it works.
Je dois dire que j’avais un tantinet tiqué à la lecture des nouvelles règles Fiba il y a quelques temps : repousser la ligne des 3 points à 6,75 m et faire de la raquette un rectangle me paraissait être un formidable baissage de culotte des Européens face à un NBA omniprésent sur la scène basketballistique. Même si je persiste à croire que l’initiative de ces changements a pour honteuse raison de vouloir-faire-comme-en-NBA-et-de-rendre-tout-le-monde-content-aux-JO-et-aux-championnats-du-monde-surtout-la-dream-team, Jean-Luc Thomas offre un début de justification acceptable dans sa dernière chronique : favoriser l‘écartement du jeu avec la possibilité de créer plus d’espace pour les intérieurs (même si agrandir la zone restrictive ne colle pas avec cette logique) qui, du fait de la chute du nombre de paniers primés, seront plus sollicités.
Mouais. Admettons.
^{1} Euphémisme, cough, cough.
Rock, Paper, Scissors 12/2/2010
Another Java forum classic: rock, paper, scissors. Or chifoumi, as it is called in France.
An interesting solution involves an enum (which I called Choice below). The only “fancy” thing in the code is checkWinner which checks if the first value is equal to the second value + 1, modulo 3 (as paper is stronger than rock, scissors stronger than paper, and rock stronger than scissors, so there’s a circular thing going on there). I haven’t bothered checking the user’s input, but that should really be done.
import java.util.Random;
import java.util.Scanner;
public class RockPaperScissors {
public enum Choice {
ROCK(0),
PAPER(1),
SCISSORS(2);
private final int value;
Choice(int value) {
this.value = value;
}
public int value() {
return value;
}
}
private int checkWinner(Choice choice1, Choice choice2) {
if (choice2 == choice1) {
return 0;
} else if (choice1.value() == ((choice2.value() + 1) %3)) {
return 1;
} else return 2;
}
private Choice getChoiceAtRandom() {
return Choice.values()[new Random().nextInt(3)];
}
private Choice readChoice() {
System.out.println("Rock, paper or scissors?");
Scanner scanner = new Scanner(System.in);
String choice = scanner.next();
return Choice.valueOf(choice.toUpperCase());
}
public void doGameLoop() {
int counter = 0;
while (counter < 3) {
Choice userChoice = readChoice();
Choice computerChoice = getChoiceAtRandom();
int winner = checkWinner(userChoice, computerChoice);
if (winner == 0) {
System.out.println("Both " + userChoice + ". It’s a tie");
} else if (winner == 1) {
System.out.println("You win! You played " + userChoice
+ " and computer played " + computerChoice) ;
} else {
System.out.println("You lose. You played " + userChoice
+ " and computer played " + computerChoice) ;
}
counter++;
}
}
public static void main(String[] args) {
new RockPaperScissors().doGameLoop();
}
}
And that’s pretty much it — connoisseurs will appreciate the use of Scanner which I usually spit upon!
I highly recommend reading the Wikipedia entry for Rock, paper, scissors, it’s quite entertaining… Did you know it’s been used in a (US) federal court?!
Finally, an interesting question! Where does System.out come from? In the aforementioned thread, I have posted an explanation that simplified what was happening behind the scene; but very much in line with Don Knuth spirit, I gave you a white lie: this is not entirely the whole truth. Though the general idea is still the same. I’ll shamelessly copy-paste some of my own response, because yes, I’m that lazy.
(All the explanation below is based on the OpenJDK 6 sources, so it might be slightly different in other VMs)
When you first look at the code in the System class, you get quite confused:
// ...
public final static InputStream in = nullInputStream();
// ...
public final static PrintStream out = nullPrintStream();
// ...
public final static PrintStream err = nullPrintStream();
// ...
private static PrintStream nullPrintStream() throws NullPointerException {
if (currentTimeMillis() > 0) {
return null;
}
throw new NullPointerException();
}
So it either returns null, or a NullPointerException?? First, let’s have at currentTimeMillis(), which is part of the condition:
public static native long currentTimeMillis();
currentTimeMillis is a native method. Native methods are methods implemented in another language (usually C or C++). This method is mapped to its C counterpart thanks to the following JNI mechanism:
public final class System {
private static native void registerNatives();
static {
registerNatives();
}
// ...
registerNatives is defined in what we call a static block, which is a block of code called only once, at classloading time. Static blocks are used for example in JDBC when you do Class.forName("my.nice.Driver"): the driver class has a static block with which it registers itself with the DriverManager, and allows you to then use the DriverManager for, say, giving you a connection. So here, the static block calls a native method, and this native method executes the C code below (Open JDK) in System.c:
static JNINativeMethod methods[] = {
{"currentTimeMillis", "()J", (void *)&JVM_CurrentTimeMillis},
{"nanoTime", "()J", (void *)&JVM_NanoTime},
{"arraycopy", "(" OBJ "I" OBJ "II)V", (void *)&JVM_ArrayCopy},
};
#undef OBJ
JNIEXPORT void JNICALL
Java_java_lang_System_registerNatives(JNIEnv *env, jclass cls)
{
(*env)->RegisterNatives(env, cls,
methods, sizeof(methods)/sizeof(methods[0]));
}
So I kind of lied when I said in my post that the streams were initialized by registerNatives. Well, not entirely, you’ll see why.
So when initializing the class variables out, in and err, currentTimeMillis should be defined, and these final variables are then set to null. If you get a NullPointerException, something utterly wrong has happened, and the JVM will probably shut down.
System gets initialized at a very specific point in the whole vm startup: it is loaded when the main thread is being kickstarted. In a file called thread.cpp, the following piece of code is executed:
// Initialize java_lang.System (needed before creating the thread)
if (InitializeJavaLangSystem) {
initialize_class(vmSymbolHandles::java_lang_System(), CHECK_0);
// ...
call_initializeSystemClass(CHECK_0);
And there you go: the System class gets loaded, and the static block is executed. We now have access to currentTimeMillis, and streams out, err and in will be null. Further down, the call_initializeSystemClass(CHECK_0) function is called, and that’s the function that actually calls the private method initializeSystemClass that calls the native methods setIn0, setOut0 and setErr0 which do initialize the streams properly.
Why are these setters (setIn0, setErr0 and setOut0) native? It’s because they are initializing final variables a second time, since they had already been set to null. Making them native allows the VM to bypass the language restriction to completely initialize the streams.
Once the VM is loaded, and again if nothing dramatic has happened, then System is available for business, along with its streams! This concludes this post, but hopefully this should the first post of new series I’m thinking of writing, called “The JVM in depth”.