NuGet basics

The definitive documentation is
If you are a console person and don’t like nody UI stuff, you can use the Package Manager Console.

I am a NuGet user, most of the time, but once in a while, publish a package for my work and personal projects.

To prepare for package creation

Of course, download NuGet.exe, and make sure NuGet.exe is in your path.

Also, you need to register with to get your api key, if you plan to share your package.

NuGet Update -self
NuGet SetApiKey Your-API-Key

Creating a package

If your package would simply contain a single assembly, you can create the package from an assembly. Otherwise, you would usually create it from a project, in which you can also benefit from tokenisation.

This creates a special nuspec file with tokens, to be replaced based on the project metaday.


  • $id$: The Assembly name
  • $version$: The assembly version as specified in the assembly’s AssemblyVersionAttribute.
  • $author$: The company as specified in the AssemblyCompanyAttribute.
  • $description$: The description as specified in the AssemblyDescriptionAttribute.

In the folder where the csproj file, run:

nuget spec
nuget pack MyProject.csproj -Prop Configuration=Release

nuget spec will generate a spec file with basic metadata.

<?xml version="1.0"?>
<package >
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2012</copyright>
    <tags>Tag1 Tag2</tags>

Once nuspec is ready, run nuget pack.
However, NuGet use the default build configuration set in the project file, and if you are a dev like me, it will be typically Debug. You wouldn’t want to publish your assembly built in Debug. so make sure to use Configuration option.

You would want to check the package you created to make sure everything necessary in there. Download NuGet Package Explorer and verify it.

Then publish it.

Add dependent assemblies to the package

Your project will have dependent assemblies (dlls), and want to include them in the package. If the dlls are references via NuGet, use . Otherwise, they are manually added, so use

<?xml version="1.0"?>
<package >
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2012</copyright>
    <tags>Tag1 Tag2</tags>
        <dependency id="Hl.Local" version="[]" />
        <dependency id="Hl.Valid" version="[]" />
    <file src="..\lib\Hl.Frame.dll" target="lib\net35" />


In dependency, if you use “[VERSION NO.]”, it will look for the exact version.

use a custom assemblyinfo from build server

You want to increase the version number from the build. Then you will need to update assemblyinfo before build the project. Then nuget package will have the verion number like Common.Framework. Unfortunately, you have to use a custom build script, something like this. (it’s a psake script)

task BuildSolution -depends AssemblyInfo {
	Message("Building version $version")
	Exec { msbuild.exe "$slnFile" /t:Clean /t:Build /p:Configuration=$buildType /v:m /nologo }

task AssemblyInfo -depends Init {
	Update-AssemblyInfo -company "$COMPANY_NAME" -copyright "$COPYRIGHT" -LiteralPath "$baseDir\CustomAssemblyInfo.cs" -AssemblyVersion $script:version

jQuery basics

This is the summary of “Fundamentals of Great jQuery Development”, which is available at

javascript is a functional language, not in a useful way, but because it treats function as its first-class citizen. It is also Object-oriented language, as it treats everything as object.

function declaration
This is what people use most of the time.

function foo(p1) {

function expression
This doesn’t have name and is anonymous.

foo(function () {});

function expression with name

foo(function f1(), "test" {});

json literals

var o = {
    foo: 1,
    bar: "test",
    alpha: {
        damian: function () { }

Here o is an object.

“new” means you create a new object based on its protytype.
If you mean a class, capitalise the first letter as convention.

function Animal() {
    this.breed = "domestic tabby";
    this.smellsLike = "candy";
Animal.prototype = {
    member1: function() { },
    member2: ""

var f = new Animal(); // create a new animal based on the prototype.
var f = Animal(); // this makes breed and smellsLike global scope, possibly overriding other breed.

In javascript, a variable’s scope is function-level. A variable is accessible within a function, even though it is declared within a block

function () {
    var i = 0;
    for (var j = 0; j <= 10; j++) {
        var x = 'test'; 
    x = 20; //this x is visible outside of the for block
x = 20: // x is not visible outside of function

Global variable or function is bad, because you cannot guarantee that only your javascript would run in the browser. You have multiple javascript from 3rd party, grease-monkey plugins, …

So, don’t declare a function in the global scope. Instead, create anonymous function and immediately execute it.

(function() {
    var i = 'test'; //as long as you use 'var', it is safe.
    this.alert('hi'); // this is global window

//If you want to pass window object
(function (w) {
    var i = 'test';


function foo() {
    this //this is an global object

function Foo() {
    this // not an global object, but this function.
var f = new Foo();

//this can be resued depending on the context.
function foo() {
    alert(this.hi); //In this case, this becomes the function, not global.
}{ hi: 'test' });{ hi: 123 });

A closure is a function that references a variable that isn’t contained within its own immediate scope.

// this variable is out of the scope;
function foo() {
    var myVar = 1;

    return function() { 
        return myVar.toString();

var myFunc = foo();
myFunc(); //This access myVar, which is outside of the function boundary. This looks trivial, but event handler takes advantage of closure.

Rails Commands

Summary of various ruby commands

.erb: embedded ruby, the primary template system for including dynamic content in web pages.


$ rails generate integration_test static_pages

Undoing things

$ rails generate controller StaticPages home help
$ rails destroy  controller StaticPages home help

$ rails generate model Foo bar:string baz:integer
$ rails destroy  model Foo

$ rake db:migrate
$ rake db:rollback
$ rake db:migrate VERSION=0

Running tests

$ bundle exec rspec spec/requests/static_pages_spec.rb

Embedded Ruby template

<% provide(:title, 'About Us') %>
<!DOCTYPE html>
    <title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>

Unix commands

mv: rename

$ mv app/views/layouts/application.html.erb foobar

Git commands

Commit, merge, and push

$ git add .
$ git commit -m "Finish static pages"
$ git checkout master
$ git merge static-pages
$ git push

RVM and bundler integration

$ rvm get head && rvm reload
$ chmod +x $rvm_path/hooks/after_cd_bundler
$ cd ~/rails_projects/sample_app
$ bundle install --without production --binstubs=./bundler_stubs

Structuremap Basics

Define the instance for your interface

public class WiringModule
    public void Initialize(IInitializationExpression x)

Call the wiring module within Application_Start() event in Global.asax.cs

protected void Application_Start()

To be continued

rails generate basics

create controller with help and home routes

$ rails generate controller StaticPages home help --no-test-framework

the option no-test-framework suppresses the default rspec test (or test::unit).

if you have created them by mistake, you can destroy them.

$ rails destroy controller StaticPages home help --no-test-framework

Creating a model is the same.

$ rails generate model Foo bar:string baz:integer
$ rails destroy model Foo


Could not find a javascript runtime.
Install node.js.

rspec basics

When you create a new site, skip generating unit test, as you want to use rspec instead.

$ rails new sample_app --skip-test-unit

Add rspec to your gemfile

group :development, :test do
  gem 'sqlite3'
  gem 'rspec-rails', '2.9.0'

group :test do
  gem 'capybara', '1.1.2'

copybara gem allows you to interact with the app with a natual English-like syntaxt.

Then run bundle install to install those gems.

$ bundle install --without production

Configure your rails app to use rspec in place of test::unit.

$ rails generate rspec:install