Skip to content

Instantly share code, notes, and snippets.

View wojtha's full-sized avatar

Vojtěch Kusý wojtha

View GitHub Profile

Using better_errors on Ubuntu with SublimeText 2

After I installed the fantastic better_errors gem, I was disappointed to notice that linking to your text editor doesn't work correctly on Ubuntu (at least, it didn't for me). Here's how I fixed it.

First, create a new desktop entry:

# /usr/share/applications/subl-urlhandler.desktop
class CorsSupport
def initialize(app)
@app = app
end
def call(env)
if preflight?(env)
env['HTTP_ORIGIN'] = 'file://' if env['HTTP_ORIGIN'] == 'null'
env['HTTP_ORIGIN'] ||= env['HTTP_X_ORIGIN']

Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

<%= nav_link 'My Page', my_path %>

When my_path is the same as the current page url, this outputs:

<a class="selected" href="http://example.com/page">My Page</a>
# Create good links for Windows and Sublime Text 2 after install SublimeProtocol:
# https://bitbucket.org/sublimator/sublimeprotocol/overview
#
# slice(9) is for remove ':' from URL eg. "C:/WWW" => "C/WWW"
def remove_colon(url)
url.slice!(9)
return url
end
@wojtha
wojtha / onchange.sh
Created February 25, 2013 13:58 — forked from senko/onchange.sh
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <[email protected]>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
@wojtha
wojtha / web_steps.rb
Created February 25, 2013 19:03 — forked from zedtux/web_steps.rb
# TL;DR: YOU SHOULD DELETE THIS FILE
#
# This file was generated by Cucumber-Rails and is only here to get you a head start
# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
# visit pages, interact with widgets and make assertions about page content.
#
# If you use these step definitions as basis for your features you will quickly end up
# with features that are:
#
# * Hard to maintain
------------------------------------------------
Top failing specs
------------------------------------------------
18 | ./spec/models/my_model_spec.rb
4 | ./spec/models/your_failing_model_spec.rb
@wojtha
wojtha / add_yard_docs.py
Last active December 14, 2015 17:59 — forked from zszugyi/add_yard_docs.py
Command for Sublime Text 2 - Adds YARD documentation to method. Supports current line or selection.
# Add YARD documentation to method.
#
# Supports current line or selection.
#
# Useful references:
# http://www.sublimetext.com/docs/2/api_reference.html
# http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/
# http://www.pythonregex.com/
#
# Key binding:
# Configure colors, if available.
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset='\[\e[0m\]'
c_user='\[\e[0;32m\]'
c_path='\[\e[1;34m\]'
c_git_clean='\[\e[0;37m\]'
c_git_staged='\[\e[0;32m\]'
c_git_unstaged='\[\e[0;31m\]'
else
c_reset=
# RSpec's subject method, both implicitly and explicitly set, is useful for
# declaratively setting up the context of the object under test. If you provide a
# class for your describe block, subject will implicitly be set to a new instance
# of this class (with no arguments passed to the constructor). If you want
# something more complex done, such as setting arguments, you can use the
# explicit subject setter, which takes a block.
describe Person do
context "born 19 years ago" do
subject { Person.new(:birthdate => 19.years.ago }
it { should be_eligible_to_vote }