Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Kreeftmeijer jeffkreeftmeijer

View GitHub Profile
View poeperdepoep.vim
" Tab -> , EOL ->
set list
set listchars=tab:💩💩,eol
View README.markdown
View remove_encoding.rb
#!/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
View token.rb
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
View frame.html
<html>
<head>
<style>
a{
display: block;
margin: 2em 1em;
}
</style>
</head>
<body>
View options.rb
# 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 Jan 23, 2015
♫ If I could turn, turn back the hands of time ♫
View turn_back_the_hands_of_time.rb
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
View sortable_list_without_javascript.rb
# 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 %>
View gist:151904
** 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'
You can’t perform that action at this time.