Blog

Moving to highlight.js

January 03, 2013 by Damien White

CSS Code

New Year, New Changes

You may have noticed a bit of a difference on the Visoft, Inc. Blogs today. I started the first (of hopefully many) changes to the site. The newer code snippets (really old ones have embedded styles, yuck :)) have a new look. What’s going on here?

Code Snippets

For many years I have utilized Alex Gorbatchov’s SyntaxHighlighter. It served me well through the years, but I started looking at other ways of blogging, namely Markdown.

If you aren’t familiar with Markdown, it is a very simple text-to-HTML conversion tool. Instead of messing with messy HTML tags, you can easily inject things like bold words, italics, or links, seamlessly while typing.

The code snippet needed for SyntaxHighlighter isn’t that complex, it’s simply a pre tag with a class of brush: LANGUAGE. In addition to the brush, you can do other things, like add line numbers and add highlighting to specific lines. It’s a nice package, albeit a little heavyweight. In addition, the default outputted HTML for a code block with Markdown is <pre><code></code></pre>. In order to use SyntaxHighlighter, you’d either have to write the code blocks using raw HTML (something you can do in Markdown) or use something on the server side to change the blocks to just <pre> tags. Not that big of a deal, but I decided to look around for other options.

Read More »

ActiveRecord Queries – Drop the Question Marks

July 30, 2012 by Damien White

You learn something new everyday! Of course it’s in the documentation, but it’s easy to overlook features.

Background

As you may or may not know, ActiveRecord lets you specify conditions in a multitude of ways. Take the first example from the docs:

class User < ActiveRecord::Base
  def self.authenticate_unsafely(user_name, password)
    where("user_name = '#{user_name}' AND password = '#{password}'").first
  end
end

authenticate_unsafely is an aptly named method. Do you see the problem? Yup, you’re opening yourself up for SQL injection. So that’s NOT the way to do things. Instead ActiveRecord allows you to use placeholders like the second example from the docs:

class User < ActiveRecord::Base
  def self.authenticate_safely(user_name, password)
    where("user_name = ? AND password = ?", user_name, password).first
  end
end

Using that syntax, the conditions are sanitized so when the query is sent to your database, no nasty injection will occur.

Read More »

Responsive Web Design – Helpful Links

June 04, 2012 by Damien White

This post looks at the basics of Responsive Web Design (RWD) and takes you on a tour around the web of some helpful links about the three principles of RWD: CSS Media Queries, Fluid Grids, and Fluid Images and Media. I hope you find these useful.

There’s tons of great things on the internet regarding RWD, so obviously I can’t include everything here. Did I miss something you wrote or that you found helpful? Let me know in the comments.

CSS Media Queries

W3C Spec For CSS Media Queries

Useful Queries

Fluid Grid Layouts

Grid layouts for webpages have become a popular web design approach. The goal is to have a solid visual and structural balance on a page.

What’s a Grid?

Table based markup was popular in the past, but it’s a poor approach.

There are many reasons why tables are bad for layout, with one of them being that the semantics are wrong. Note that semantics are an important part of HTML5.

Grids give a page structure and consistency like tables, but without the rigidness.

Fluid Grid

Fluid Images

Major Ruby OData Update v0.1.0

December 07, 2011 by Damien White

OData_logo_MS_smallIt’s here! I’m happy to announce a major release of ruby_odata, v0.1.0. There are many enhancements found in this release so let’s dig in and see what’s new.

There is one thing that we need to get out of the way first, a breaking change. In v0.0.10 and below, queries and some instances of calls to save_changes would return a single entity if there was only one returned. This was confusing and could lead to errors. As a consumer of the gem, you wouldn’t know if a call to the Service’s execute method was a single object or an enumerable. Instead of you having to guess, those calls now return enumerables all the time. This applies to calls to execute and save_change additions. Updates, deletes, and add_link calls (we’ll get to those in a minute), as well as batch saves all return Booleans, but single save_change add calls will return an enumerable because those results are parsed similar to execute calls.

Now that that’s out of the way, let’s look at the new features.

Read More »

Ruby OData Update v0.0.10

September 26, 2011 by Damien White

OData_logo_MS_small I’m happy to announce that today, ruby_odata has continued to move forward by adding additional features and fixing bugs.

I skipped an update for v0.0.9, so let’s revisit what was added/fixed back then. The major change was support for self-signed SSL certificates. That addition was courtesy of J.D Mullin. I’m sure you remember his contributions back in v0.0.8 when he added Basic HTTP Authentication. Aside from J.D.’s contributions, the library was refactored to only make one call to the service for building classes and collections. Finally, a few bug fixes wrapped up the release.

Now onto v0.0.10. A lot of changes were implemented in this release that ended up allowing for wider support for ruby_odata. Thanks to input from Michael Koegel (@konfusius), Alvaro Tejada (@Blag), Ingo Sauerzapf (@IngoS11), and Juergen Schmerder (@schmerdy) (I apologize if I missed anyone!), ruby_odata now supports (at least basic functionality) for SAP NetWeaver GateWay.

Another big change is the initial support for feed customizations. Properties may not be represented within the collection of an entity. Currently ruby_odata supports SyndicationTitle and SyndicationSummary, but adding the other syndication options should be easy to support. If you can supply me with the metadata and a copy of the output that includes the additional feed customizations, I will be happy to add them (or feel free to fork the project and add them yourself).

Here’s are the complete list of changes for v0.0.10:

  • New Features
    • Added the ability to pass additional parameters that are appended to the query string for requests
    • Added initial support for feed customizations (SyndicationTitle and SyndicationSummary)
    • Enhanced ruby_odata’s awareness of classes based on the metadata instead of relying on results that are returned
  • Bug Fixes
    • Fixed issues with nested collections (eager loading)
    • Handled ArgumentError on the Time.parse for older versions of Ruby; used DateTime.parse instead if Time.parse fails
    • Removed the camelize method call when building the root URL for collections (reported by mkoegel, issue #3 on github)
    • Handled building results (classes) where the category element is missing but there is a title element instead (reported by mkoegel, issue #3 on github in the comments)
  • Other
    • Change HTTP port to 8989 since 8888 conflicts with the Intel AppStore
    • Refactored service step for HTTP calls where the service address is defined within the step making it easier to make changes in the future

For the next release, I hope to continue to fix issues, finally add support for inheritance, add the ability to call a custom WebGet methods added to the service, and hopefully namespacing of entities to limit collisions. Do you have other requests? Add them to the issues list on GitHub. The previous Lighthouse site for issues has been closed in favor of using GitHub.

Silverlight 4 Multi-Binding Converter Enhancement

September 15, 2011 by Damien White

We have been using Colin Eberhardt’s MultiBinding Converter for Silverlight for quite a while now. It was great until we realized a problem. When the MultiBinding Converter was off screen (hidden), it would throw a binding error stating that it couldn’t convert null to whatever (in our case it was an integer in one converter and FontWeight in another).

The Solution

The solution is rather easy. Add a property called TargetNullValue to MultiBinding.cs in Colin’s source. There’s no “magic” in this name, you can call it whatever you want. TargetNullValue seems to make the most sense for its purpose in this case, and is the name of the property on the actual Silverlight Binding that we’ll be setting in the next step.

/// <summary>
/// Gets or sets the target null value.
/// </summary>
public object TargetNullValue { get; set; }

Then, hop over to MulitBindings.cs and change the binding (line 110) to utilize the TargetNullValue property on the binding for the ConvertedValue like so:

// bind the ConvertedValue of our MultiBinding instance to the target property
// of our targetElement
Binding binding = new Binding("ConvertedValue")
{
  Source = relay,
  Mode = relay.Mode,
  TargetNullValue = relay.TargetNullValue
};

Now, when you use the MultiBinding, just fill in the TargetNullValue property, for example:

<TextBlock ...>
    <multi:BindingUtil.MultiBindings>
        <multi:MultiBindings>
            <multi:MultiBinding TargetProperty="FontWeight" TargetNullValue="Normal" Converter=...>
                <multi:MultiBinding.Bindings>
                    <multi:BindingCollection>
                        ...
                    </multi:BindingCollection>
                </multi:MultiBinding.Bindings>
            </multi:MultiBinding>
        </multi:MultiBindings>
    </multi:BindingUtil.MultiBindings>
</TextBlock>

Now my Debug Output window isn’t filled with needless binding errors!

Silverlight 4 Drop-Down Problems in Popup

September 12, 2011 by Damien White

Are you running Silverlight and using a Popup and a “drop-down” control like a ComboBox (or DatePicker, TimePicker, etc) as a child? You may be seeing some odd behavior when you expand the ComboBox. The “drop-down bit” ends up positioned from the left of your screen, not where it is supposed to be positioned. Hmmm.

Turns out the solution is easy, but not easy to find. I’m hoping this post will help someone else out and prevent others from beating their heads against a wall. Ready?

Turn off the DropShadowEffect on the Popup.

This solution is thanks to Rjacobs’s reply on the Silverlight forums. Also, vote for the issue on the Microsoft Connect site.

Introducing a Ruby Wrapper for Google Books API

August 10, 2011 by Damien White

Books.  Personally, I own a ton of them.  Add in my wife’s collection, and phew.  A few years ago, I decided to get my collection under control.  I have bookcases upon bookcases all over the place and I would lose track of my books.  I wanted to catalog my collection, so I built a site to do just that.

The time has come to rebuild the project.  It’s pretty old, is missing a lot of features, has spun off into another site as well, and, and, and…  That’s for another post.  Anyway, back to the matter at hand.

For the past couple of years, I used to get my book information from Amazon’s Product Advertising API for Affiliates. Well, times change, and thanks to the State of Connecticut, I’m no longer an Amazon affiliate.  I told you that story to tell you this one…

Read More »

Entity Framework – Removing Foreign Keys from the Entity Model

March 18, 2011 by Damien White

DatabaseDesignEntity Framework 4.0 has brought some great new features to Entity Framework (although I am SO looking forward to EF 4.1.  Hooray for a code-only option).  One of the new features of EF 4 is the ability to include foreign key columns in your model.  This option will include the foreign key as a property within your entity in addition to the Navigation Property.  The advantage to doing this is that you can now perform linkage between entities with only needing to fill the foreign key property instead of filling the navigation property.  It works pretty well, unless you want to have something like a zero or 1 association (0..1).  Attempting to change the multiplicity in the designer for the association yields the following error:

Error 113: Multiplicity is not valid in Role in relationship X. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be *.

Blah.  The solution I found to fix it was to remove the foreign key association on the 0..1 entity.  Now how do we go about doing this?

This post assumes that you added entities with the foreign key columns included in your model and now you need to make changes to your associations.

Read More »

Ruby OData Update v0.0.8

March 14, 2011 by Damien White

OData_logo_MS_smallIt has been WAY too long since an update of ruby_odata was released.  I’m happy to announce that version 0.0.8 was released today.  The biggest change, thanks to J.D. Mullin, is support for Basic HTTP Authentication.  It’s an awesome enhancement and very easy to use.  All you need to do is pass in the username and password as constructor arguments when instantiating a service like so:

require 'lib/ruby_odata'

svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc", { :username =&gt; "bob", :password=&gt; "12345" }

In addition to the big change by @jdmullin, the following changes are apart of the new version:

  • Support for nullable primitive types being returned from an OData service.
  • A change in ActiveSupport 3.0.x broke additions in ruby_odata when you associate a previously saved entity.  This has been corrected, and ActiveSupport 2.3.x (tested 2.3.11) and 3.0.x (tested 3.0.5) are now supported. 
  • Ruby 1.9.2 is now supported.

Other “backend” type enhancements were added:

  • Removed Jeweler for releasing gems
  • Moved to bundler
  • Updated README to reflect new changes
  • Updated DB management so that testers aren’t required to move files around
  • Fixed gemspec to list the development gems
  • Developers can just do a “bundle install” to get all the required gems

One interesting thing that I found while testing is that Ruby 1.9.2 is much faster when running Cucumber tests on Windows.  I was using Ruby 1.8.7-p330 vs 1.9.2-p180 on Windows (RubyInstaller rocks!).  Here’s a snapshot:

CucumberRubyVersionComparison

Note there is a bit of a problem using Ruby 1.9.2 w/ Cucumber on Windows.  The problem is that when using bundler or “gem install,” the json gem gets installed as the x86-mingw32 version.  Running cucumber on Windows with Ruby 1.9.2 (using the incorrectly compiled json gem) yields a msvcrt-ruby18.dll error.  The way I fixed the error was to install the RubyInstaller DevKit, and then reinstall the gem “correctly” using:

gem uninstall json
gem install json --platform=ruby -v 1.4.6

What we are doing is uninstalling the incorrect copy of the json gem and then installing v1.4.6 of json using the –platform=ruby flag which will involve the DevKit to compile the gem for us.  Note that the json gem version required by Cucumber 0.10.0 is ~> 1.4.6, and there is a new version out, so the -v 1.4.6 forces the correct one.  Found the solution on StackOverflow,  but it seems that there should be a better way to solve this, perhaps with bundle-config?