Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Justin R http://blog.kineticweb.com/

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

Really Kill Rails (as well as Restart)

More lovely alias commands... this time to kill/restart Rail's script/server from any Terminal session or login on your box... (as long as your the same user).

alias dierails='ps -a|grep "/usr/local/bin/ruby script/server"|grep -v "grep /usr"|cut -d " " -f1|xargs -n 1 kill -KILL $1'
alias resetrails='ps -a|grep "/usr/local/bin/ruby script/server"|grep -v "grep /usr"|cut -d " " -f1|xargs -n 1 kill -HUP $1'

Archive Flagged Items from NetNewsWire into Yojimbo

This lil Ruby-OSA script will allow you to import your "Flagged Items" in NetNewsWire as Web Archive Items in Yojimbo. Thus allowing you to save RSS articles for off-line viewing/storage.

#!/usr/local/bin/ruby
['rubygems', 'rbosa'].each {|lib| require lib}
nnw = OSA.app('NetNewsWire')
yojimbo = OSA.app('Yojimbo')

nnw.subscriptions.find { |s| s if s.display_name == 'Flagged Items' }.headlines.each do |article|
  unless yojimbo.web_archive_items.map { |f| f.source_url }.include?(article.url)
    archived = yojimbo.make(OSA::Yojimbo::WebArchiveItem, 
                            article.url, 
                            :name => article.title)
    # Adjust this for slower/faster bandwidth connections (or your feeling lucky, punk)
    sleep(5)
    # Uncomment below to remove the flagged items upon successfully archiving
    # if archived.name == 'untitled' && archived.source_url.empty?
    #   puts "!!! #{article.title} does not look to be imported !!!"
    # else
    #   article.delete
    # end
  end
end

Alias to a Nice Default Gitk

Just a really quick and easy shell alias for my preferred defaults for Git's repository and branch viewer, Gitk.

This runs "gitk"...
...including all branches,
...outputting errors to the black hole,
...and any extra command-line arguments.

# Run like this
# gitk --since="2 days ago" &

alias gitk="gitk --all $1 2>/dev/null"

Recursively Remove .DS_Store files in OS X

This shell alias will recursively remove all .DS_Store files from the current directory up.

alias rmdsstores='find ./ -type f | grep .DS_Store | xargs rm'

Rails Environment Specific Capistrano Includes/Overrides

This cap technique allows you to include environment specific tasks and namespaces as well as override anything in the master deploy.rb. Its rather simplistic.

Add your environment specific cap scripts into RAILS_ROOT/config/deployments/.

Example command-line usage:

# RAILS_ENV=production cap deploy

...or...

# cap deploy rails_env=beta


# Example needed variables at the top of your deploy.rb

set :default_env,  'beta'
set :rails_env,     ENV['rails_env'] || ENV['RAILS_ENV'] || default_env
set :extra_deploys, 'config/deployments/'

...

# Now add this to the bottom of your deploy.rb, last thing to load.

if extra_deploys && File.exists?(extra_deploys+rails_env+".rb")
  puts "Loaded #{extra_deploys+rails_env}.rb" if load extra_deploys+rails_env
else
  puts "Could not find #{extra_deploys+rails_env}.rb"
end



You may change your default_env or any other piece to fit into your deployments. The secret is "load" method call burried in that latter code portion above. The reason you load at the end of your deploy.rb is so you can override anything defined above that call in your environment specific scripts.

Git-diff last two commits through TextMate

I believe this is how svn diff operates... but anyway, this alias will allow you to diff the last two commits in Git through TextMate. If you have a theme that supports Diff's then you'll see the differences clearly. Remove the last pipe statement (the mate part) to expose your diff in the console.

alias gitdiff='git log|grep commit|cut -d " " -f2|head -n 2|xargs -n 2 git diff -R|mate'
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS