Skip to content

Instantly share code, notes, and snippets.

View qcam's full-sized avatar

Cẩm Huỳnh qcam

View GitHub Profile
@qcam
qcam / how-to-create-different-shapes-in-css.md
Created April 28, 2014 09:16
How to create different shapes in CSS

The Cheetsheet

ruby_tests screenshot

@qcam
qcam / ruby-send.md
Created May 2, 2014 03:09
How to call a symbol method in Ruby

How to call a symbol method in Ruby

class Klass
  def hello(*args)
    "Hello " + args.join(' ')
  end
end
k = Klass.new
k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
@qcam
qcam / rescue-error-rails.md
Last active August 29, 2015 14:00
Rescue Error in Controller

Use rescue_form to avoid code duplication in Controller

class DealsController < ApplicationController
  before_filter :authenticate_user!, except: [:index, :show, :list]
  before_filter :authenticate_proposer, only: [:edit]

  rescue_from StandardError, with: :show_errors
  rescue_from Order::OrderNotFound, with: :show_errors
 
@qcam
qcam / random-ruby-tips.md
Last active August 29, 2015 14:00
30 Randoms Ruby (Rails) Tips - by Winston TeoFrom https://speakerdeck.com/winston/random-ruby-and-rails-tips

##Ruby (Rails) tips

####1. Array Initialization

if x.is_a?(Array)
  x.each { |x| puts x } 
else
  puts x
end
@qcam
qcam / heroku-commands.md
Created May 3, 2014 00:36
Some Heroku helpful commands

Some Heroku commands

Open the bash shell

heroku run bash

Open Rails console

@qcam
qcam / voting-star-css.md
Created May 3, 2014 00:51
Voting star with CSS
  • Star Rating with only CSS
<div class="star-wrapper">
  <a class="star" href="javascript:alert(1)"></a>
  <div class="star-wrapper">
    <a class="star"></a>
    <div class="star-wrapper">
      <a class="star"></a>
      <div class="star-wrapper">

Setup a WYSIWYG editor with CKEditor. Includes instruction for Rails_Admin

  • Add gem 'ckeditor' to your Gemfile and bundle
  • Checkout https://github.com/galetahub/ckeditor for instruction to generate the correct model to generate for uploading of files (eg. ActiveRecord + Paperclip)
  • Run rake db:migrate
  • Add //= require ckeditor/override in your application.js (before require_tree .)

To configure the editor to be used in Rails_Admin, follow this https://github.com/sferik/rails_admin/wiki/CKEditor

Sample Rails_Admin model config

@qcam
qcam / rails_admin-customise_authorisation.md
Last active August 29, 2015 14:01
How to customise authorisation rails_admin

How to authorize rails_admin

config.authenticate_with do
  warden.authenticate!
end

config.authorize_with do
  redirect_to main_app.root_path unless current_user.has_role?(:admin)
end
@qcam
qcam / view-helper-datetime-options.md
Last active August 29, 2015 14:01
Configure datetime options
= simple_form_for @time_slot, url: booking_path, method: :patch do |f|
  = f.input :start_time, :as => :datetime, :minute_step => 30, :include_seconds => true, :discard_year => true, :datetime_separator => ' &mdash; ', :time_separator => ' - '
  = f.input :id, as: :hidden
  = f.submit "Book this slot", class: 'btn'