Skip to content

Instantly share code, notes, and snippets.

#---
# Excerpted from "Agile Web Development with Rails, 3rd Ed.",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/rails3 for more book information.
#---
class AddTestData < ActiveRecord::Migration
<div id="product-list">
<h1>Listing products</h1>
<table>
<% for product in @products %>
<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
<td>
<%= image_tag product.image_url, :class => 'list-image' %>
</td>
<td class="list-description">
<dl>
@moniyax
moniyax / 0_README.md
Created July 21, 2011 17:14 — forked from netzpirat/0_README.md
Continuous CoffeeScript testing with Guard and Jasmine

Continuous CoffeeScript testing with Guard and Jasmine

This Gist shows how to set up a Rails project to practice BDD with CoffeeScript, Guard and Jasmine. You can see this setup in action on Vimeo

  • Install Gems with Bundler with bundle install
  • Define your guards with mate Guardfile
  • Initialize Jasmine with bundle exec jasmine init
  • Configure Jasmine with mate spec/support/yasmine.ym
  • Start Guard with bundle exec guard
@moniyax
moniyax / coffeescript_converter.rb
Created July 30, 2011 16:28 — forked from phaer/coffeescript_converter.rb
A trivial CoffeeScript.org -> Javascript plugin for jekyll ( https://github.com/mojombo/jekyll ). Put this file in '_plugins/' and write a YAML header to your .coffee files (i.e. "---\n---\n")
module Jekyll
require 'coffee-script'
class CoffeeScriptConverter < Converter
safe true
priority :normal
def matches(ext)
ext =~ /coffee/i
end
@moniyax
moniyax / SQLSchemaDumpWriter
Created September 5, 2011 15:48
sample C# code to dump sql schema to a FluenMigrator migration file
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using FluentMigrator;
using FluentMigrator.Model;
using FluentMigrator.SchemaDump.SchemaWriters;
public abstract class BadgeJob
{
protected BadgeJob()
{
//start cycling on initialization
Insert();
}
//override to provide specific badge logic
protected abstract void AwardBadges();
@moniyax
moniyax / SelectiveModelBinding.cs
Created September 14, 2011 12:36
Selective Model Binding
interface ICreatePerson
{
string Name { get; set; }
string Sex { get; set; }
int Age { get; set; }
}
interface IUpdatePerson
{
string Name { get; set; }
@moniyax
moniyax / RelatedQuestionsByTags.sql
Created September 16, 2011 08:28
Related Questions By Tags
/*Source: http://stackoverflow.com/questions/246841/how-to-find-the-records-with-most-common-tags-like-the-related-questions-in-stac */
select qt.question_id, count(*)
from question_tags qt
where qt.tag in
( select qt2.tag
from question_tags qt2
where qt2.question_id = 123
)
group by qt.question_id
@moniyax
moniyax / AdminLinksInView.cs
Created September 24, 2011 20:31
Admin Links In View
//source: http://stackoverflow.com/questions/1236739/how-can-i-avoid-unmaintanable-code-in-asp-net-mvc-views
<td>
Html.LinkList(", "
ActionLinks.ViewDetails(item),
ActionLinks.DeleteAndConfirm(item),
ActionLinks.Approve(item))
</td>
class ActionLinks
@moniyax
moniyax / CsharpMixins.cs
Created October 1, 2011 07:17
Csharp Mixins
//Idea from: http://stackoverflow.com/questions/9033/hidden-features-of-c#238462
class Program
{
static void Main(string[] args)
{
Console.WriteLine(new Foo().Dance());
Console.WriteLine(new Bar().Dance());
Console.ReadKey();
/*Output: