Ubuntu 12.10 Disable System Program Problem Detected

Posted by dan on January 26, 2013 No comments
sudo nano /etc/default/apport
enabled=0

Mercurial settings

Posted by dan on January 25, 2013 No comments
[extensions]
hgext.bookmarks =
rebase =
hgext.purge =

[ui]
username = Daniel Worthington-Bodart <***@*****.com>

[merge-tools]
meld.executable = meld
meld.args = $local $base $other -o $output

[auth]
google.prefix = code.google.com
google.username = **********
google.password = **********
google.schemes = http https

[alias]
pull = pull --rebase
nuke = !$HG revert --all --no-backup ; $HG purge

Setting the Default Schema with Oracle JDBC Driver

Posted by dan on January 24, 2013 No comments

If you use C3PO you can make it do it when it checks the connection out.

As properties:

c3p0.preferredTestQuery=alter session set current_schema=animals
c3p0.testConnectionOnCheckout=true

As Java code:

ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setPreferredTestQuery("alter session set current_schema=animals");
dataSource.setTestConnectionOnCheckout(true);

Downside is this will happen every time the connection is taken out of the pool

If you are using a JDBC connection yourself you could just do:

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = getConnection("jdbc:oracle:thin:@//server:1521/instance", "username", "password");
connection.createStatement().execute("alter session set current_schema=animals"));

I also posted it to StackOverflow

Why Functional Programming in Java is NOT Dangerous

Posted by dan on January 23, 2013 1 comment

This is a quick post in response to Elliotte Rusty Harold article titled Why Functional Programming in Java is Dangerous.

Lets look at the some of the points made:

  • Lazy evaluation
  • JIT / JavaC can’t optimise
  • Recursion

The example that Elliotte uses comes from Bob Martins article done in clojure

(take 25 (squares-of (integers)))

Lets show the same things written in Java with TotallyLazy (Disclaimer: I wrote it) :

range(1).map(squared).take(25);

You could write the same thing with most functional libraries for Java, as pretty much all of them have lazy Lists or lazy Sequences. In fact the clojure example is doing exactly the same thing: integers returns Seq. If you tried to make it return a PersistentList you would have exactly the same OutOfMemoryError exception.

The article goes on to say “the JIT and javac can’t optimize functional constructs as aggressively and efficiently as they can in a real functional language.” Obviously clojure is a JVM language that produces byte code and so runs with the same JIT as Java.

The final point is that you can’t do recursion with Java, well that’s just not true. IBM have been doing tail call optimisation with their Java compiler since I believe version 1.3. Clojure doesn’t even support it implicitly, you need to either explicitly call the recur macro or use an additional library.

For tail call optimisation in Java you could try JCompilo (Disclaimer: I wrote it). Here is an example:

@tailrec
public static int gcd(int x, int y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

If you are reading this article and thinking well Java still doesn’t have lambda’s till Java 8, then you might want to look at Håkan Råberg’s Enumerable.Java. Here is the previous example using a lambda:

range(1).map(λ( n, n * n)).take(25);

Now I’d like to make clear that I think clojure is an amazing language and it inspires me every time I work with it. I’d also like to say that a lot of good stuff is coming in future versions of Java which will make this a much nicer experience but until then it’s creating a great space for people like myself and Håkan to innovate. Java 8 retort here

Samsung Series 9 (NP900X3C-A05UK) Ubuntu/Linux: Wake up when I open the lid

Posted by dan on January 13, 2013 No comments

So one of the last things that wasn’t perfectly working was coming out of suspend when I opened the lid. First thing you need to so is find the name of the LID switch:

ls /proc/acpi/button/lid/
LID0

Mine seems to be LID0 or LID1. You can then check it’s current state by doing:

cat /proc/acpi/button/lid/LID0/state
state:      open

Now all you need to do is add this to the wake up list

sudo -s
echo LID0 > /proc/acpi/wakeup

That’s it,

Samsung Series 9 (NP900X3C-A05UK) Ubuntu/Linux setup for power management and keybindings

Posted by dan on December 7, 2012 3 comments

Ubuntu 12.10 works pretty well out of the box (for me it was just power management and keybindings that needed work), see Ubuntu wiki if you have any other issues . Using powertop I was able to understand what needed doing. What follows are my settings:

/etc/rc.local

#!/bin/sh -e

# Temp disable ethernet port
modprobe -r r8169

# Disable wake up on lan if I do use ethernet port
ethtool -s eth2 wol d;

# Temp disable bluetooth
modprobe -r btusb

# Adjust backlight to start much lower
echo 11 > /sys/class/backlight/acpi_video0/brightness

# - NMI Watchdog (turned off)
echo 0 > '/proc/sys/kernel/nmi_watchdog';

# - SATA Active Link Powermanagement
echo 'min_power' > '/sys/class/scsi_host/host0/link_power_management_policy';

# - USB Autosuspend (after 2 secs of inactivity)
for i in `find /sys/bus/usb/devices/*/power/control`; do echo auto > $i; done;
for i in `find /sys/bus/usb/devices/*/power/autosuspend`; do echo 2 > $i; done;

# - Device Power Management
echo auto | tee /sys/bus/i2c/devices/*/power/control > /dev/null;
echo auto | tee /sys/bus/pci/devices/*/power/control > /dev/null;

# - CPU Scaling (on demand scaling governor for all CPU's
for i in `find /sys/devices/system/cpu/*/cpufreq/scaling_governor`; do echo ondemand > $i; done;

exit 0

On the keybingings the only keys that didn’t work were some of the Fn Keys

/lib/udev/keymaps/samsung-other

0xCE prog1              # FN+F1 System Settings (NOT WORKING)
0x89 brightnessdown     # Fn+F2
0x88 brightnessup       # Fn+F3
0x82 switchvideomode    # Fn+F4 CRT/LCD (high keycode: "displaytoggle")
0xF7 f22                # Fn+F5 Touchpad on
0xF9 f23                # Fn+F5 Touchpad off
0x97 kbdillumdown	# FN+F9 Keyboard backlight down
0x96 kbdillumup         # FN+F10 Keyboard backlight up
0xB3 silentmode         # FN+F11 Silentmode (NOT WORKING)
0xD5 wlan               # FN+F12 WiFi  (NOT WORKING)

/lib/udev/keymaps/force-release/samsung-other

# list of scancodes (hex or decimal), optional comment
0xCE # FN+F1 System Settings
0x89 # FN+F2 Brightness down
0x88 # FN+F3 Brightness up
0x82 # FN+F4 Switch video mode
0xCE # FN+F1 System Settings
0x89 # FN+F2 Brightness down
0x88 # FN+F3 Brightness up
0x82 # FN+F4 Switch video mode
0xF7 # Fn+F5 Touchpad on
0xF9 # FN+F5 Turn touchpad off
0x97 # FN+F9 Keyboard backlight down
0x96 # FN+F10 Keyboard backlight up
0xB3 # FN+F11 Silentmode
0xD5 # FN+F12 WiFi

The volumn keys and trackpad all worked for me so I didn’t change them.

Gnome 3 / GSettings Sucks: Export/Importing your Keyboard shortcuts

Posted by dan on October 23, 2012 No comments

Previous to Gnome 3 I had a nice simple flat file for my keyboard settings, that I just unzipped into .gconf and all was good. Now Gnome is copying the very bad idea of a registry from Windows, you have go through the gsettings API or tool.

Locate the keyboard shortcut schema “org.gnome.desktop.wm.keybindings”

Now lets “export” them

gsettings list-recursively org.gnome.desktop.wm.keybindings > keybindings

Now unfortunately there does not appear to be a way to import that file, so I just hacked the file. Adding “gsettings set” to the front and quoting the values.
So

org.gnome.desktop.wm.keybindings show-desktop ['<Super>d', '<Primary><Super>d', '<Super>d']

becomes

gsettings set org.gnome.desktop.wm.keybindings show-desktop "['<Super>d', '<Primary><Super>d', '<Super>d']"

I’ve created some keybindins that use the Windows/Super key for window management, plus this don’t conflict with IntellJ

Blog Memory: Accessing Vigor 120 Modem when bridged with Buffalo WZR-HP-AG300H (DD-WRT)

Posted by dan on October 6, 2012 No comments

I found this article ip6.com/projects/?p=363

So I just changed the IP address to match the default that the Vigor modem uses:

ifconfig eth1:1 192.168.2.9 netmask 255.0.0.0
iptables -I POSTROUTING -t nat -o eth1 -d 192.0.0.0/8 -j MASQUERADE

It’s not perfect but it’s a start.

My Speakerconf 2012 slides

Posted by dan on August 26, 2012 2 comments

presumptions.bodar.com/

My QCon Video is available here

Posted by dan on July 19, 2012 No comments

www.infoq.com/presentations/Crazy-Fast-Build-Times-or-When-10-Seconds-Starts-to-Make-You-Nervous

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.