hacking, misctech, webstuff
I’ve been thinking for a while about moving my simple web site and blog to a different platform. I’m currently paying to host everything on a traditional hosting service. Ten years ago, this was really the only option if you wanted buy a domain and put a web site out there (there was also self hosting with dynamic DNS, but I was never brave enough to open up my home network).
Using cookies with HttpClient
This simple code snippet shows how to store and use cookies from a web request using the .Net HttpClient. For example, if an API or site sends a token or authentication cookie, you may need to store it and send it on all subsequent requests to show that you are authenticated. This would be for a session-based service. The key is to create a single CookieContainer instance and a single HttpClientHandler instance to hold it.
Trying out Windows Live Writer
hacking, website
Scott Hanselman has been trumpeting Windows Live Writer for some time now. I’ve been hesitant to try it out because I’m a control freak and I was convinced that Live Writer wouldn’t do things correctly. Well, he blogged about it again today so I’m giving it a try (with this post). It was the comments on his post that swayed me. Live Writer has improved quite a bit since last time I tried it.
Last.fm Recent Tracks with AngularJS
angularjs, bootstrap, hacking
AngularJS is an MVC framework for javascript. It is best suited for round-tripping resources with a RESTful service. In this post, I will simply get a list of recent tracks from Last.fm, treating each track as a resource. The Last.fm API is documented here. There is no round-tripping in this example. I’ll also be utilizing Twitter Bootstrap for layout. To start, create the AngularJS application and a controller for recent tracks.
Thumbnail Gallery with Flickr, Bootstrap, and Javascript
I recently created a thumbnail gallery of my latest Flickr photos using the Flickr feeds API, Twitter Bootstrap, and Javascript/jQuery. There is no server side code for this solution, and the client side code is really simple. To start, create a blank html page (I like to start with the HTML5 Boilerplate). Make sure you include the Bootstrap css and jQuery. I used the Thumbnails component of Bootstrap for the gallery layout.
Project – La Cocina
I’ve been working on a new Rails application for storing our recipes. It’s at a point where it is being hosted and used by us. Some of the style is borrowed (stolen) from Martha Stewart’s blog. The big feature of La Cocina is it’s ability to pull in recipes from a number of other recipe sites. I’m using the nokogiri gem to do screen scraping for recipe data. There’s an admin interface for creating new screen scrapers (which I call “scarfers”), so it’s easy to add new recipe sites by entering DOM paths (CSS or XPath) and some other options.
Show SVN revision number in a Rails application
This is a hack to display the Subversion revision in a Rails application using Capistrano to insert the current revision number on each deploy. Create a partial that will contain the revision number. For example, _~/app/views/layouts/revision.html.erb. You can put anything in that file, as it will be overwritten by Capistrano on each deploy. The word “Development” or “Current” seems a good choice. In the page where you want to display the revision number (probably in the application layout), render the partial.
FizzBuzz one-liner in C#
FizzBuzz: _Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Reference_ Console.WriteLine(String.Join(Environment.NewLine, Enumerable.Range(1, 100) .Select(i = (i % 3 == 0) ? new { n = i, w = "Fizz" } : new { n = i, w = "
jQuery Autocomplete and Rails
This is an example of how I used the jQuery Automcomplete Widget with Rails 3.2 for a recipe search field. Some of the jQuery stuff mentioned below is included out of the box with a new Rails application. Make sure the jQuery gem is referenced in the Gemfile gem 'jquery-rails' Include the jQuery javascripts in app/assets/javascripts/application.js //= require jquery //= require jquery_ujs //= require jquery-ui Download one of the jQuery-ui css files, or a custom one, and put it in one of you asset locations.
WCF Client and the “using” Statement
As I was researching patterns and practices for a WCF client implementation, I came across a bug in the .Net implementation of ClientBase (whether it’s actually a bug is arguable). It’s well documented on the web, but it could cause major headaches if you happened to miss it. The core of the issue is that ClientBase implements IDisposable. With this knowledge, just about any programmer would naturally wrap its usage in a using{} block.
Find/Kill a Linux Process by Name
hacking, misctech
I was doing some research to figure out how to easily kill a Linux process given part of it’s name. It’s fairly simple to do it manually, but if you didn’t already know, programmers are lazy. The first thing I was doing… ps aux | grep Foo find the process ID (PID) with my eyes, and then kill it… kill -9 123456 Next, I started finding complex piped commands to find and extract the PID.
Simple Moq
I recently worked on a project in which 90% of its tests were integration tests because the core purpose of the project was to interact with external entities. In an effort create more unit tests, I employed Moq (and lots of refactoring). This is an example of basic Moq usage. Let’s say we have a repository that gets documents from a database. The assumption is that a repository interface, IDocumentRepository, is being implemented.
Complex XSDs as Embedded Resources
I was recently tasked with validating XML files against a very complex set of XSD schema files. This is easily accomplished if your XSD files live on the filesystem, because the .Net xml resolver can find referenced schemas via a relative or absolute Uri. In my case, the schema files were compiled as embedded resources in my project. As expected, the XML schema loader didn’t know how to find referenced schemas – it was likely searching for them in the path of the running application.
MVC3 + MongoDB + Autofac
I recently posted a brief summary of creating a recipe database. I decided to expand on that and go into the implementation details of using ASP.NET MVC3 with MongoDB and Autofac. This code depends on the NoRM driver for MongoDB, Autofac, and MVC3 (and it’s dependencies). This is by no means the only (or best) way to do things, but this is how I chose to do it. I’ve simplified the repository to one method for brevity, but you’d obviously want to add all of the required CRUD operations.
A Diet and an Application
I’ve started on the Paleo Diet, which, of course, means I have to create a software application to go along with it. I decided this was a good time to give MVC3 and MongoDB a test drive. After diving in, I realized that I could benefit from some dependency injection via MVC3’s DependencyResolver. I’ve been wanting to learn Autofac, so I threw that in as the container. This was sweet, as it injected my repository implementations into my controllers with very little setup.
What I’m Working On
hacking, website
Here’s what I’m working on What I worked on. Right now it’s just a basic display of feeds from some of my social networks. I’d like to fancy it up a bit at some point, perhaps with some nice jQuery tooltips. I’m using the SimplePie PHP library to fetch the feeds (each one asynchronously). The design is borrowed from Popurls. I know it’s not that interesting, but it’s fun for me.

© 2017 knoone.info. All rights reserved.