Skip to content

Instantly share code, notes, and snippets.

View seyhunak's full-sized avatar
🏆
Polyglot Programmer

Seyhun Akyürek seyhunak

🏆
Polyglot Programmer
View GitHub Profile
@seyhunak
seyhunak / database.yml.example mysql2
Created February 8, 2012 11:39 — forked from erichurst/database.yml.example mysql2
Rails 3 database.yml examples
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@seyhunak
seyhunak / bootstrap_form_builder.rb
Created January 28, 2012 17:58
Makes building forms that follow Twitter Bootstrap 2.0's conventions easier
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
def control_group(method, *args, &block)
options = args.extract_options!
error_class = object.errors[method].present? ? 'error' : ''
@template.field_set_tag(nil, class: ['control-group', error_class].join(' ')) do
label(method, options[:label], class: 'control-label') +
@template.content_tag(:div, class: 'controls') do
doc = Nokogiri::HTML::DocumentFragment.parse(@template.capture(&block))
if help_block = doc.at_css('.help-block')
help_block.before inline_errors(method)
@seyhunak
seyhunak / gist:1694192
Created January 28, 2012 12:49 — forked from mislav/gist:17371
haml2erb
class ErbEngine < Haml::Engine
def push_script(text, preserve_script, in_tag = false, preserve_tag = false,
escape_html = false, nuke_inner_whitespace = false)
push_text "<%= #{text.strip} %>"
end
def push_silent(text, can_suppress = false)
push_text "<% #{text.strip} %>"
end
end
@seyhunak
seyhunak / Action Mailer
Created January 24, 2012 11:30 — forked from fxn/Action Mailer
Ruby on Rails v3.2.0 CHANGELOGs
## Rails 3.2.0 (January 20, 2012) ##
* Upgrade mail version to 2.4.0 *ML*
* Remove Old ActionMailer API *Josh Kalderimis*
@seyhunak
seyhunak / bootstrap_form_builder.rb
Created January 23, 2012 11:43 — forked from cbmeeks/bootstrap_form_builder.rb
Twitter Bootstrap Form Builder
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
delegate :capture, :content_tag, :tag, to: :@template
%w[text_field text_area password_field collection_select].each do |method_name|
define_method(method_name) do |name, *args|
errors = object.errors[name].any?? " error" : ""
error_msg = object.errors[name].any?? content_tag(:span, object.errors[name].join(","), class: "help-inline") : ""
content_tag :div, class: "clearfix#{errors}" do
@seyhunak
seyhunak / _flash.html.erb
Created January 17, 2012 18:38 — forked from potomak/_flash.html.erb
Rails flash messages using Twitter bootstrap
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert-message <%= flash_class(level) %>">
<a class="close" href="#">×</a>
<%= content_tag :p, flash[level] %>
</div>
<% end %>
<% end %>
@seyhunak
seyhunak / gist:1499751
Created December 20, 2011 01:19 — forked from vijaydev/gist:1472145
Rails 3.2.0 Changelogs

Railties 3.2.0 (unreleased)

  • Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting config.reload_classes_only_on_change to false. José Valim

  • New applications get a flag config.active_record.auto_explain_threshold_in_seconds in the environments configuration files. With a value of 0.5 in development.rb, and commented out in production.rb. No mention in test.rb. fxn

  • Add DebugExceptions middleware which contains features extracted from ShowExceptions middleware José Valim

  • Display mounted engine's routes in rake routes Piotr Sarnacki

@seyhunak
seyhunak / index.js.erb
Created December 16, 2011 23:41 — forked from ryanb/index.js.erb
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@seyhunak
seyhunak / gist:1471973
Created December 13, 2011 12:29 — forked from moro/gist:1024620
Kaminari and pushState
(function($){
$('.pagination a[data-remote=true]').live('ajax:success', function(e){ window.history.pushState('', '', $(e.target).attr('href')) })
$(window).bind('popstate', function(){ $.ajax({url:window.location, dataType:'script'}) ; return true });
})(jQuery);
@import "twitter/bootstrap";
// -------------------------------
// Links
@linkColor: #8b59c2;
@linkColorHover: darken(@linkColor, 10);
// Grays
@black: #000;