Author Archives: dan
Excel Integration the old school way: Web Queries (IQY) and Data Queries (DQY)
An alternative approach to just doing CSV export (which is fast and more cross platform/app) is to use web queries (.iqy files that point to fairly HTML) or data queries (.dqy extension but point to the DB)
Pro
- Supports refreshing data / live data model
- Web based integration
- Very easy to do
- Works with all versions since excel 97
- They support linking back into you app via urls (IQY only) so we had cells that said edit that took you back to the web app.
- Auto sorting, pivoting is a doddle
Cons
- No support for different sheets in the same book (you can work around this by having a master workbook that aggregates from multiple web queries sheets.) CSV has the same problem.
- There are some methods to write back but they all seemed a bit sucky to me (you can create forms that push the data back from specific cells but it’s pretty ugle UI wise). I have always ended up writing a tiny bit of VBA that just does a POST to some url (embed this in your master workbook etc) or just an edit link that goes back to the web app
- Some annoying pop ups (See below)
Notes
- With DQY you expose username password and database details to user but you get full SQL support / joins etc.
- Make sure you set Cache-Control headers ( I use either “public” or “private, must-revalidate” )
IQY Example
WEB 1 server/money.html?query=blah+blah+blah&sortBy=market_value
DQY Example
XLODBC 1 DRIVER=SQL Server;SERVER=server\blah;UID=regulatory;PWD=l33t;DATABASE=showMeTheMoney SELECT * FROM trades ORDER BY market_value DESC
Disable Excel Pop.reg
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options] "QuerySecurity"=dword:00000002
Ubuntu 12.10 Disable System Program Problem Detected
sudo nano /etc/default/apport enabled=0
Mercurial settings
[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
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
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
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
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
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)
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
presumptions.bodar.com/