Skip to content

Instantly share code, notes, and snippets.

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
@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 (
@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 / 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 / gist:981417
Created May 19, 2011 18:37
SQL Server commands to backup/restore database
BACKUP DATABASE MyDbName TO DISK = 'C:\MSSQL\Backup\mydbname_backup.bak'
RESTORE DATABASE MyDbName FROM DISK = 'C:\MSSQL\Backup\mydbname_backup.bak' WITH RECOVERY, REPLACE
@joshuaflanagan
joshuaflanagan / Console command
Created June 1, 2011 22:23
Turn off Always Start When Debugging for all web projects (run within Nuget powershell console)
get-project -all | %{ $_.Properties | ?{ $_.Name -eq "WebApplication.StartWebServerOnDebug" } | %{ $_.Value = "False"} }
@joshuaflanagan
joshuaflanagan / SystemClock.cs
Created June 14, 2011 16:30
Stubbable replacement for DateTime.Now
public static class SystemClock
{
static SystemClock()
{
Live();
}
public static DateTime Now
{
@joshuaflanagan
joshuaflanagan / gist:1026358
Created June 15, 2011 02:25
Resharper demo
Assumes Resharper IntelliJ/IDEA Resharper keybindings
Create a new ASP.NET MVC Web application (Internet)
Open HomeController.cs and start typing outside of HomeController, but within the namespace:
cl[Tab]WorkController[Enter]
p[Tab]Ac[Tab]Show(){[Enter]
return _workflowService.GetResult();[Enter]
*position cursor on _workflowService
@joshuaflanagan
joshuaflanagan / package.bat
Created June 24, 2011 02:57
Examples of how to build all Nuget nuspec files in a folder
@ECHO OFF
SETLOCAL
SET VERSION=%1
SET NUGET=buildsupport\nuget.exe
FOR %%G IN (packaging\nuget\*.nuspec) DO (
%NUGET% pack %%G -Version %VERSION% -Symbols -o artifacts
)
@joshuaflanagan
joshuaflanagan / publish_nuget.rb
Created June 24, 2011 03:07
Example rake task that downloads CI artifacts to publish nuget packages to the official feed
desc "Downloads from CI and pushes nuget packages to the official feed"
task :release, [:package] do |t, args|
require 'open-uri'
release_path = "#{buildsupport_path}/nuget_release"
clean_dir release_path
# The @teamcity_build_id is a unique identifier for the build configuration (looks like "bt234"). You can usually figure it out from your project url
artifact_url = "http://teamcity.codebetter.com/guestAuth/repository/downloadAll/#{@teamcity_build_id}/.lastSuccessful/artifacts.zip"
puts "downloading artifacts from teamcity.codebetter.com"
artifact = open(artifact_url)