Friday, May 2, 2014

Quick tidbits

One of the reasons I like Project Euler is that it gives you a chance to expand your knowledge of whatever language you're using...

For instance, today I learned about Fixnum#fdiv (forces float division instead of integer division) in Ruby:
2/4       # 0
2.div(4)  # 0
2.fdiv(4) # 0.5
Sure there's a ton of other ways to do it, but this was succinct and to the point.

And the RSpec =~ operator for array equality - it's basically the same thing as ==, except that order doesn't matter.

[1,2] == [2,1] # false
[1,2] =~ [2,1] # true
Two simple things that I'd not had a reason to use before. Will I use them all the time, nope. But I'm glad to have found them.

Monday, January 27, 2014

Logging sql queries from korma

Wanted to see what sql is actually getting executed from a webapp running korma - seems fairly easy since I stumbled upon blackwater.
Inside your project.clj, add blackwater and clj-time...
(defproject foo "0.1.0-SNAPSHOT" 
  :description "Zap bug tracker"
  :dependencies [
    ;; other deps omitted
    [blackwater "0.0.9"]
    [clj-time "0.6.0"]]
Inside your ns:
(ns.foo
  (:use korma.db korma.core)
  (:require [black.water.korma :refer [decorate-korma!]]))

(decorate-korma!)
You'll get nice output like:
SELECT "project".* FROM "project"| took:31ms
SELECT "project".* FROM "project" WHERE ("project"."id" = ?)| took:4ms

Reloading lein repl

So, I'm working through the book Seven Web Frameworks in Seven Weeks from the awesome Pragmatic Programmers and I'm on the Clojure section (keep in mind that I don't know Clojure ^^) but quitting/restarting to get the repl to pick up changes just plain sucks.

Here's a solution I found on SO:

Add tools.namespace to your project.clj dependencies.

e.g.
:dependencies [
  # ...
  [org.clojure/tools.namespace "0.2.4"]]

After you start up the lein repl:
user=> (use '[clojure.tools.namespace.repl :only (refresh)])
nil

... make some changes to a clj file ...

user=> (refresh)
:reloading (hello.core hello.core-test zap.models)
:ok
It's not 100% automatic, but it beats quitting/restarting. Though it does appears you have to type that use statement every time after you refresh...

Tuesday, June 11, 2013

How do I debug/run an app in Android Studio to a Nexus 7

So, it turns out developer mode is a little tricky to find on a Google Nexus 7. Go to "Settings" -> "About Tablet" then click EXACTLY 7 TIMES on the "Build Number". (After three presses, you'll get a message "You are four steps from being a developer”) This will open up "Developer Options" in the menu. Choose that. Enable "USB debugging"

Thursday, May 16, 2013

Chrome - Network error - Failed

So, let's say you're downloading a large file in Chrome and it fails... what do you do?

Well, if you're at home or work or somewhere with a fast network, you probably just start the download again (there's no resume functionality).

But what if you're at a conference or coffee shop or somewhere without a fast internet connection.  Starting the download from the beginning could cost you a significant amount of time.
Instead:

Open your downloads folder (e.g. ~/Downloads in OSX if you haven't changed the defaults)
Locate the file you were trying to download, it will have the extension .crdownload
Rename the file, removing the ".crdownload" extension (e.g. myfoo.zip.crdownload should be renamed to  myfoo.zip)
Open a terminal window in the same directory
Use wget to resume the file (the -c flag will continue the download you're already started)
wget -c <url_of_the_file_you_were_downloading>

Thursday, January 17, 2013

getting py2cairo installed on osx w/ brew

(this is more of an gist that a post)
> ./waf configure

  ./options()
Setting top to                           : /Volumes/HDD/Downloads/py2cairo-1.10.0
Setting out to                           : /Volumes/HDD/Downloads/py2cairo-1.10.0/build_directory
  ./configure()
Checking for 'gcc' (c compiler)          : ok
Checking for program python              : /usr/bin/python
Checking for python version              : (2, 7, 1, 'final', 0)
Checking for library python2.7           : yes
Checking for program python2.7-config    : /usr/bin/python2.7-config
Checking for header Python.h             : yes
Checking for program pkg-config          : /usr/local/bin/pkg-config
Checking for 'cairo' >= 1.10.0           : not found
The configuration failed
(complete log in /Volumes/HDD/Downloads/py2cairo-1.10.0/build_directory/config.log)


 After a TON of trial and error, followed by brew install , here's what I came up with: 
 export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig:/usr/local/Cellar/libpng/1.5.13/lib/pkgconfig:/usr/local/Cellar/freetype/2.4.10/lib/pkgconfig:/usr/local/Cellar/fontconfig/2.10.1/lib/pkgconfig:/usr/local/Cellar/pixman/0.28.0/lib/pkgconfig:/usr/local/Cellar/cairo/1.12.8/lib/pkgconfig:/opt/local/lib/pkgconfig

> ./waf configure
> sudo ./waf install

Monday, June 11, 2012

one-line update for all pom versions in multi-module project

We have a multi-module Maven project with many children, so it's a little annoying to bump the version number. Here's a one-liner to do it, just replace _OLD_ and _NEW_ with the old version and new version, respectively.
for f in `find . -name pom.xml`; do sed 's/_OLD_/_NEW_/' $f > $f.new; mv $f.new $f; done
for example:
for f in `find . -name pom.xml`; do sed 's/1.1.23-SNAPSHOT/1.1.24-SNAPSHOT/' $f > $f.new; mv $f.new $f; done

*DON'T FORGET TO CHECK THE DIFF (you ARE using Git, right?)*

** Update (thanks jamcole)**

Or even easier, use the Maven versions plugin (from the top-level project):
mvn versions:set