Skip to content

Instantly share code, notes, and snippets.

@joshuaflanagan
joshuaflanagan / growl.rb
Created April 3, 2011 23:04
Include this from your rakefile to get a (Windows) growl notification when rake process completes
unless ENV["BUILD_NUMBER"] # do not use growl when running on the CI server
task :growl do
Rake::Application.growl
end
module Rake
class Application
# override task execution so that growl task is always called last
alias :raw_top_level :top_level
@joshuaflanagan
joshuaflanagan / SensitiveCaseDataRestriction.cs
Created January 21, 2011 20:29
Only show cases with IsSensitive=false unless the current user has "View Sensitive Cases" permission
using DovetailCRM.Core.Authorization;
using DovetailCRM.Core.Domain.Workflow;
using FubuFastPack.Querying;
using FubuMVC.Core.Security;
namespace DovetailCRM.Core.Web.Query
{
public class SensitiveCaseDataRestriction : IDataRestriction<Case>
{
public void Apply(IDataSourceFilter<Case> filter)
@joshuaflanagan
joshuaflanagan / s.bat
Created January 16, 2011 15:39
Launch IIS Express from the command line
@ECHO OFF
SET IIS="c:\Program Files (x86)\IIS Express\iisexpress.exe"
SET ARG=%1
REM Default to curret directory if no path provided
IF [%ARG%] == [] (
SET root=%CD%
GOTO launch
) ELSE (
module Kernel
def maybe(*path)
return path.inject(self) do |obj, method|
return nil if obj.nil?
if method.respond_to? :keys
obj.send(method.first[0], *method.first[1])
else
obj.respond_to?(:keys) ? obj[method] : obj.send(method)
end
end
class Hash
def deep(*path)
path.inject(self) {|h,k| h.respond_to?(:fetch) ? h.fetch(k, nil) : h}
end
end
#example
stuff = {
:foo => {
:bar => nil
<!-- the expression in the container is used by the contained LableFor and InputFor -->
<div for="x => x.FirstName">
<div class="shiny">{ Label }</div>
<div class="happy">{ Input }</div>
</div>
<!-- or if you don't need a container, use a "virtual", non-printing tag
<surround for="x => x.FirstName">
<dt class="shiny">{ Label }</dt>
@joshuaflanagan
joshuaflanagan / restoredb.sql
Created July 14, 2010 16:45
Restore a SQL Server database
ALTER DATABASE mydbname SET SINGLE_USER With ROLLBACK IMMEDIATE
RESTORE DATABASE mydbname FROM DISK = 'c:\path\to\file.bak' WITH REPLACE
public static HtmlTag TableFor<T>(this IFubuPage view, IEnumerable<T> data, params string[] columns) where T : class
{
var properties = typeof(T).GetProperties();
// optionally limit the columns to display
if (columns.Length > 0) properties = properties.Where(p => columns.Contains(p.Name)).ToArray();
var table = new HtmlTag("table");
var header = new HtmlTag("thead");
table.Child(header);
foreach (var property in properties)
##### Using ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
C:\code>irb
irb(main):001:0> include FileTest
=> Object
irb(main):002:0> exists? 'foo'
=> false
irb(main):003:0>
### Using IronRuby 1.0
C:\code>ir
desc "Generate the database schema"
task :db do
$:.unshift('.\src\MyApp\bin') # Add the website bin folder to the load_path so that assembly dependencies are found
require 'MyApp' # MyApp is my ASP.NET web app assembly DLL
MyApp::Database.BuildSchema # Database.BuildSchema is a static method
puts 'Database rebuilt'
end