Skip to content

Instantly share code, notes, and snippets.

View seyhunak's full-sized avatar
🏆
Winning The Life

Seyhun Akyürek seyhunak

🏆
Winning The Life
View GitHub Profile
@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 / 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 / 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 / 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 / on_update.task.rb
Created February 15, 2012 12:51 — forked from peterc/on_update.task.rb
Rake task to automatically run something (i.e. specs) when code files are changed
# Rake task to automatically run something (i.e. specs) when code files are changed
# By Peter Çoopér
#
# Motivation: I couldn't get autotest to run on my Sinatra project for some reason but realized
# it didn't require overengineering. Just detect when a file is changed and then re-run the specs!
#
# Examples:
# # rake on_update "rake"
# # rake on_update "spec spec/user_spec.rb"
#
@seyhunak
seyhunak / edit.html.erb
Created February 22, 2012 20:34 — forked from daz/edit.html.erb
twitter-bootstrap-rails ERB template
<%= render :partial => 'form' %>
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@seyhunak
seyhunak / rails-export-csv.rb
Created April 9, 2012 15:05 — forked from bcalloway/rails-export-csv.rb
Use FasterCSV to export an ActiveRecord object in Rails
### /config/environment.rb
config.gem 'fastercsv'
### /config/routes.rb
map.connect '/users/export', :controller => 'users', :action => 'export'
### /app/models/user.rb
# find all students and pass to controller export action for export to csv
def self.find_students
find_by_sql("select students.firstname, students.lastname, students.grade, students.homeroom, students.phone, students.email, students.relationship, users.firstname, users.lastname, accounts.school from students, users, accounts where students.user_id = users.id and accounts.id = users.account_id")
@seyhunak
seyhunak / gist:2602279
Created May 5, 2012 13:09 — forked from anonymous/gist:14120
Google Analytics Image Request Builder
require 'net/http'
class GoogleAnalytics
BASE_URL = "http://www.google-analytics.com/__utm.gif?"
def self.create_url(request, options)
params = {}
raise(ArgumentError, "Can't create GA URL without an urchin code") unless params[:utmac] = options.delete(:ga_code)
raise(ArgumentError, "Can't create GA URL without a page URI") unless params[:utmp] = options.delete(:page_uri)
utmdt = options.delete(:description) || "-" # page description
@seyhunak
seyhunak / page_inject.coffee
Created May 10, 2012 06:52 — forked from ntreadway/page_inject.coffee
Simple page inject for JQuery Mobile and Rails Partials
# Used to dynamically add a rails page view when using Jquery Mobile
# Author Nick Treadway @nicktea
@insert_page = (id, content) ->
page = $("<article id="+id+" data-role='page' data-url="+id+" data-add-back-btn='true'>" + content + "</article>")
page.appendTo('body')
$('a' + '#' + id).click ->
$.mobile.changePage(page, {transition: "slide"})
# Use (your-view.haml)