Skip to content

Instantly share code, notes, and snippets.

SmartUrlHelper.configure do |url|
url.for ->model{ model.is_a?(Comment) } do |helpers, model|
helpers.post_comment_path(model.post, model)
end
# TODO: Add a convenience method for matching on type:
# url.for(Comment) do |helpers, model|
# helpers.post_comment_path(model.post, model)
# end
end
@joshuaflanagan
joshuaflanagan / xml_parser.rb
Created January 9, 2012 02:22 — forked from kmile/xml_parser.rb
A small nokogiri xml reader DSL.
# A small DSL for helping parsing documents using Nokogiri::XML::Reader. The
# XML Reader is a good way to move a cursor through a (large) XML document fast,
# but is not as cumbersome as writing a full SAX document handler. Read about
# it here: http://nokogiri.org/Nokogiri/XML/Reader.html
#
# Just pass the reader in this parser and specificy the nodes that you are interested
# in in a block. You can just parse every node or only look inside certain nodes.
#
# A small example:
#
@joshuaflanagan
joshuaflanagan / bt.sh
Created December 10, 2011 16:24
Toggle Bluetooth
# copy blueutil from http://www.frederikseiffert.de/blueutil/ to ~/bin
# I created this as a Shell Extension in Alfred and assigned a global hotkey to it (Command+Ctrl-B)
if ~/bin/blueutil status|grep -q on; then ~/bin/blueutil off; else ~/bin/blueutil on;fi
@joshuaflanagan
joshuaflanagan / gist:1412771
Created December 1, 2011 02:02
Git aliases
# add to your ~/.gitconfig
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
@joshuaflanagan
joshuaflanagan / gist:1302978
Last active September 27, 2015 17:07
Example of jquery.when
$.when( getTweets('austintexasgov'),
getTweets('greenling_com'),
getTweets('themomandpops')
).done(function(atxArgs, greenlingArgs, momandpopsArgs){
var allTweets = [].concat(atxArgs[0]).concat(greenlingArgs[0]).concat(momandpopsArgs[0]);
var sortedTweets = sortTweets(allTweets);
showTweets(sortedTweets);
});
var getTweets = function(user){
@joshuaflanagan
joshuaflanagan / nuget_tool.bat
Created June 24, 2011 03:19
Example batch file to execute a tool from a Nuget package
@ECHO OFF
SETLOCAL
REM This can be used for any .exe installed by a nuget package
REM Example usage: nuget_tool.bat nunit-console.exe myproject.tests.dll
SET TOOL=%1
FOR /R %~dp0\source\packages %%G IN (%TOOL%) DO (
IF EXIST %%G (
SET TOOLPATH=%%G
GOTO FOUND
)
@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)
@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 / 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 / SystemClock.cs
Created June 14, 2011 16:30
Stubbable replacement for DateTime.Now
public static class SystemClock
{
static SystemClock()
{
Live();
}
public static DateTime Now
{