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 / font-asset-rails-heroku.md
Created May 3, 2014 00:20
[Rails Assets Pipeline] How to make web fonts work on Heroku

How to make web fonts work on Heroku

Add the fonts path to your production.rb and development.rb

# Add the font path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# Include font files to Assets
config.assets.precompile &lt;&lt; /\.(?:svg|eot|woff|ttf)$/
@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 / capybara-wait-for-ajax.md
Created May 3, 2014 00:41
Wait for AJAX in Capybara

Wait for AJAX Capybara

Add wait_for_ajax to your helper

def wait_for_ajax
  Timeout.timeout(Capybara.default_wait_time) do
    loop do
      active = page.evaluate_script('jQuery.active')
 break if active == 0
@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