Skip to content

Instantly share code, notes, and snippets.

View softcraft-development's full-sized avatar

Craig Walker softcraft-development

View GitHub Profile
tell application "Terminal"
activate
do script with command "cd ~/my/development/directory"
do script with command "cd ~/my/development/directory && mate ."
do script with command "cd ~/my/development/directory && script/server"
do script with command "cd ~/my/development/directory && script/console"
do script with command "cd ~/my/development/directory && autotest"
end tell
//---- SASS ----
// common code
=column_size(!size, !padding=1%)
width = !size - !padding
padding:
right = !padding
=equal_width_columns(!count)
#!/bin/ruby
require 'fileutils'
files = Dir['*.sql']
files.each do |file|
p file
typestring = `file #{file}`
if !typestring.include? "ASCII"
output = `iconv -f UCS-2 -t UTF-8 #{file}`
File.open(file, "w") do |f|
require 'fileutils'
include FileUtils
require 'pathname'
namespace :paperclip do
desc "Remove Paperclip attachment directories with no entity"
task :gc => :environment do
current_trash = ((Pathname.new trash) + (Pathname.new Time.now.strftime("%Y-%m-%d.%H:%M:%S"))).cleanpath
# This algorithm assumes that the attachments have a :path starting with "#{IMAGES_ROOT}/[class name]/:attachment/:id/"
# This matches my setup, but may not match yours.
#!/usr/bin/env ruby
# Merges the current branch into the specified branch after checking out that branch.
# Usage:
# git merge-into [branch]
# [branch] defaults to "master" if not specified
# "sprint" is my convenience library for handling external processes.
@softcraft-development
softcraft-development / concatenate_non_nil_strings.rb
Created December 19, 2009 21:44
Concatenate two strings if not nil
class String
def &(value = nil, default = "")
value ? self + value.to_s : default.to_s
end
end
# Mostly for consistency; not terribly useful
class NilClass
def &(value = nil, default = "")
default.to_s
@softcraft-development
softcraft-development / hash_extensions.rb
Created January 3, 2010 00:04
Add dynamic defaults to a Hash
require 'rubygems'
require 'shoulda'
class Hash
def with_defaults( default_blocks )
new_hash = Hash.new do |hash, key|
value = default_blocks[key]
if value.respond_to? :call
value = value.call
end
@softcraft-development
softcraft-development / numeric_extensions.rb
Created January 6, 2010 06:30
Constrain a value between two values
class Numeric
def between( *values )
low = values.min
high = values.max
[[low,self].max, high].min
end
end
require "test/unit"
require "shoulda"
@softcraft-development
softcraft-development / find_synonym_remote_targets.sql
Created January 8, 2010 18:52
Show the remote server data source for synonyms targeting linked servers in SQL Server 2005
select
sk.name as LocalSchemaName,
sn.name as SynonymName,
sn.base_object_name as FullTargetName,
substring( sn.base_object_name, 2, charindex(']', sn.base_object_name) - 2) as LinkedServerName,
sv.data_source as RemoteServerName,
substring(
sn.base_object_name,
charindex('[', sn.base_object_name, 2) + 1,
charindex(
@softcraft-development
softcraft-development / restful_routing.asax.cs
Created January 18, 2010 21:52
Two RESTful routes for global.asax in ASP.NET MVC
public static void RegisterRoutes(RouteCollection routes)
{
// Matches /Controller/ModelID (with an optional /Action)
routes.MapRoute(
"Details",
"{controller}/{id}/{action}",
new { action = "Details" }
);
// Matches /Controller; typically this represents a list of all models for a particular controller.