Mind Dump
Random daily ramblings of an unfocused developer
Monday, May 20, 2013
Web API FromUrl and FromBody
While the WebAPI certainly seems modeled after that, and it's a noble effort, I've been struggling to get routes working the way I want running into issues with nested resources and using parameters in the url. The preferred solution seems to be to use IQueryable and OData, I don't use an ORM that implements IQueryable, and I wasn't willing to switch. So I have stumbled onto the pattern of using FromUrl to at least pass parameters in a more complex than the standard way.
Sunday, April 7, 2013
An Evernote backed Journal using Vim/Emacs
I journal quite a bit and my holy grail has been using my favorite text editor (Vim or Vim bindings) with Evernote to store the everything in a smart searchable format. Today I stumbled onto a neat little tool that makes this all happen called Geeknote http://www.geeknote.me/. It's written in Python and works fine on my Mac.
Installing Geeknote
#!/bin/sh# Download the repository.git clone git://github.com/VitaliyRodnenko/geeknote.gitcd geeknote# Launch Geeknote and go through login procedure.python geeknote.py login#change vim to whatever you want it to bepython geeknote.py settings --editor vim
#!/bin/sh#change checkout_dir to match where you've checked out the latestcheckout_dir=~/Documents/geeknote#change notebook to whatever notebook you use as your journalnotebook=Journaltitle=$1if [ -z "$1" ]thentitle=$(date +%Y-%m-%d)fiecho creating a note named $title in the $notebook notebookpython $checkout_dir/geeknote.py create --title $title --notebook $notebook --content "test"python $checkout_dir/geeknote.py edit --note $title --notebook $notebook --content "WRITE"
Writing Journal Entries
journal #creates a note in journal with todays date as the title
journal custom_title #no spaces allowed and will use the title specified
Summary
Monday, February 18, 2013
Ruth’s Story
Cleft
A “Normal” Life
Pompe Disease
Home
Routine checkups can be so very non-routine
Christmas
Joy and Heartache
A Lesson Of Resilience
Sunday, September 25, 2011
Rail 3.1 CI setup with Jenkins, Test Unit & SimpleCov on OS X Lion.
Running Jenkins as a hidden user
First I noticed that jenkins was running as the "daemon" user, this obviously wasn't going to work for github and rvm needs. So I did some googling and had some guides to get Jenkins running as a specific user. I did the following (sourced from http://colonelpanic.net/2011/06/jenkins-on-mac-os-x-git-w-ssh-public-key/ ). Note: That's really $PASSWORD up above. This gives you a prompt to enter that password. Next you'll need to stop the Jenkins service and edit the plist and start the service back up.You're plist file should end up like this.
RVM issues
Now my next issue was despite what I'd read elsewhere I was unable to get Jenkins to use the default ruby provided by RVM. So I just pasted the commands that I would run anyway in the "Execute Shell" build step.Getting Jenkins to see tests
I've been using Test:Unit/Minitest lately just to keep more consistent with my day to day work. However I haven't found a way to get my tests to show when using the "Execute Shell" task. I found a little gem called ci_reporter that exports to the standard junit format, unfortunately it doesn't work with minitest yet. That's ok I haven't done anything that Test:Unit doesn't support so far so I added the the following to my Gemfile (note the part about unit-test 2.0):Running "rake ci:setup:testunit test" should give you a bunch of xml files in tests/reports. Now we need to tell Jenkins where to find those reports so add a post build action to pick them up as junit reports.
Rcov reports
This was pretty easy.- Install Jenkins plugin for RCov (it's in the plugin list in the admin section).
- add simplecov and semiplecov-rcov to your Gemfile.
- configure Jenkins rcov plugin to look in coverage/rcov
- add the following 4 lines to the TOP of your tests/test_helper.rb file:
In closing
This took a fair amount of time, but the end result was quite satisfying. I now have CI with tests, tests coverage, RVM to target different versions of Ruby and bundler to make sure my Gem environment is sane.Friday, February 4, 2011
The difficult definition of professional software development
- Code should always be well commented
- Maintainable code has unit tests and well named methods therefore needs little if any comments
- Class explosion is to be avoided at all costs
- Many small simple well named classes are the key to well organized code
- Unit tests really don't test anything useful
- Dependency injection leads to an unusable mess
- Dependency Injection is a very useful tool for making your code extensible and easily reused"
- Inheritance leads to solid code reuse
- Inheritance is the strongest coupling of your code you can have
- Functional programming simplifies and minimizes the complexity of your code
- Functional programing just makes my eyes bleed!
- Static global references are 'just programming' and something you have to learn how to manage to make simple easy to understand code
- Static global spiderwebs are crippling to maintenance and program lifetime
This leads me to question how much do software principles matter when taking them out of the context of yourself but viewing it in a bigger picture? Thinking about it, 95% of the software that I actually like probably wasn't using any TDD at any point in time and certainly violates a number of things that I would consider required for "professional software". I keep reinforcing this fact every time I checkout the source of a major software project I've used for years and gasp in horror at the spaghetti code I find.
Worse still the different schools of thought are not compatible in the slightest, and one side views the other side as wholly unprofessional (granted for different reasons) to the point that I've realized I myself was perceived as the one being "amateur" by those with a different definition of what makes good and bad software. I of course unfortunately often thought the same of them, regardless of how I felt about them personally.
Anyway, this is all food for thought and I have not yet come to any conclusion what it all means. I know I've tried coding under other schools of thought and while through practice I was able to deliver well enough, I'm far slower and more error prone with no TDD, big mega classes, and avoiding dependency injection.
Sunday, September 19, 2010
Java IoC containers and classpath scanning (or what I’ve been looking for from .NET for months)
Frustrated with the typical way I saw IoC used in Java where every example I found involved thousands of lines of XML
and/or Java code to configure Java beans or components. This is very different than IoC typically used in .NET where most IoC containers allow
you to "autowire" in their terminology up every class in an assembly with a couple of lines of code. Having been coding in that fashion
for several years in .NET I was dismayed when none of my fellow Java coders that I worked with or knew personally had any concept
of the equivalent functionality, and instead informed me the IDE would be my help in maintaining these massive XML files.
Not content with their answers I burrowed into Spring, Guice and PicoContainer docs and found "classpath scanning" which is roughly
equivalent to "autowire" in .NET. Below is an example of this in Spring 3:
MyStuff.java (my main class note his has 2 dependencies which you can view on my github repo)
package org.foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service //one way of marking this as a component to register
public class MyStuff {
private final DependencyWithNoInterface first;
private final DependencyInterface second;
@Autowired //tells spring which constructor to use for it's dependencies
public MyStuff(DependencyWithNoInterface first, DependencyInterface second) {
this.first = first;
this.second = second;
}
public void run(){
System.out.println("foo me");
first.foo();
second.superFoo();
}
}
appContext.xml (seems you still need some XML)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.foo"/>
</beans>
Application.java (the initialization)
package org.foo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Application {
public static void main(String args[]){
ApplicationContext ctx = new ClassPathXmlApplicationContext("appContext.xml"); //the IoC container
MyStuff stff = ctx.getBean(MyStuff.class); //my fully injected class
stff.run();
}
}
Now I’m sure for the .NET developers familiar with StructureMap, Windsor, Autofac, etc this is completely unimpressive. I’m also sure there are Java developers that are somewhat unimpressed with this but for reasons that involve holding onto giant configuration artifacts. Manual IoC component registration falls where hand writing SQL for trivial data access does for me, extra repetitive work that has been solved years ago. I worked in factories a decade ago, and therefore now have a low tolerance for similar activity as a professional.
Edit:
It appears you can forgo XML as well in your main class use a different Application context and add the refresh and scan lines
package org.foo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Application {
public static void main(String args[]){
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan("org.foo"); //scans the org.foo package
ctx.refresh(); //needed to load them for some reason
MyStuff stff = ctx.getBean(MyStuff.class);
stff.run();
}
}
Thursday, July 15, 2010
Anti-Pattern: Too much of your application is about interacting with external resources
- Stored procedures with a fair amount of conditional logic or complicated business rules buried in a sub-query (some would argue sprocs at all).
- Web pages with lots of conditional output again encoding business rules in snippets of view logic. if else checks that display the latest price for something if before and certain date or a default price.
- The majority of ‘unit tests’ require a database, or web and application server to be up and running.
- The majority of code files make reference to language default I/O or database libraries.
- Hours are spent trying to determine if differences in version of infrastructure are the cause of certain bugs.
- Changing database schema results in hours of refactoring, as hundreds of querys and sprocs are hunted through to see if this index or that index is being properly hit.
It is not testable in the slightest in any practical sense. You will be counter with well that with that sort of application and making everything a front to back test that you KNOW when things are working, yes but you RARELY if EVER know in a quick sense why things are not working. If i can reliably eliminate any chance that my actual code or business logic is the cause of a problem, if all of my fancy business rules are in something that can be run thousands of times a second, then I can throw all sorts of corner cases at my code base and not increase my verification time. If the majority of my application is business logic and plain old code then I can save my slow manual testing to the areas that are so bullet proof and only have a slice of my application doing front to back testing to yes, make sure things really work.
Note: Cross posted from Polyglots R Us.
Permalink


