Skip to content

Instantly share code, notes, and snippets.

View jeffkreeftmeijer's full-sized avatar
🦞

Jeff Kreeftmeijer jeffkreeftmeijer

🦞
View GitHub Profile
" Tab -> , EOL ->
set list
set listchars=tab:💩💩,eol:¬
#!/usr/bin/env ruby
Dir['**/*.rb'].each do |path|
lines = File.readlines(path)
new_lines = lines.dup
lines.each do |line|
if line =~ /^# encoding: utf-8/i || line !~ /\S/
new_lines.delete_at(new_lines.index(line))
else
@jeffkreeftmeijer
jeffkreeftmeijer / Gemfile
Last active August 29, 2015 14:07
Import
gemspec
module Concerns::Token
def self.included(base)
base.after_initialize(:set_token)
end
def set_token
self.token = SecureRandom.hex if new_record?
end
end
@jeffkreeftmeijer
jeffkreeftmeijer / frame.html
Created November 27, 2014 18:03
Anchors in iframes
<html>
<head>
<style>
a{
display: block;
margin: 2em 1em;
}
</style>
</head>
<body>
# Option 1
info = if publication
"Title: #{ publication.title } (ID: #{ publication.id })"
else
'N/A'
end
# Option 2
info = case publication
when Publication then puts "Title: #{ publication.title } (ID: #{ publication.id })"
@jeffkreeftmeijer
jeffkreeftmeijer / turn_back_the_hands_of_time.rb
Created January 23, 2015 11:04
♫ If I could turn, turn back the hands of time ♫
puts "♫ If I could turn, turn back the hands of time ♫"
puts "♫ Then my darlin' you'd still be mine ♫"
class Time
def self.now
Time.new(2015, 1, 23)
end
end
# index.html.erb
<ul id="projects">
<% @projects.each_with_index do |project, index| %>
<% content_tag_for :li, project do %>
<%= project.name %>
<%= button_to('up', :action => 'sort', :projects => @projects.swap(index, index -1)) if index > 0 %>
<%= button_to('down', :action => 'sort', :projects => @projects.swap(index, index +1)) if index < @projects.length - 1 %>
<% end %>
<% end %>
** Invoke test (first_time)
** Execute test
** Invoke test_inner (first_time)
** Execute test_inner
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:ext:bin:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/test_helper.rb" "test/test_nifty_authentication_generator.rb" "test/test_nifty_config_generator.rb" "test/test_nifty_layout_generator.rb" "test/test_nifty_scaffold_generator.rb"
/Library/Ruby/Gems/1.8/gems/rubigen-1.4.0/lib/rubigen/lookup.rb:9:in `const_missing_before_generators': stack level too deep (SystemStackError)
from /Library/Ruby/Gems/1.8/gems/rubigen-1.4.0/lib/rubigen/lookup.rb:13:in `const_missing_before_generators'
from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/rails_generator/lookup.rb:13:in `const_missing'