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 / hardcore-rpc.md
Last active August 30, 2016 00:53
[HARDCORE] RPC.md

What's RPC?

In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (this is what it differs from REST) to execute in another address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction.

There are multiple implementation of RPC: ONC RPC, JSON-RPC, XML-RPC, gRPC, SOAP, etc.

How RPC works?

  1. The client calls the client stub. The call is a local procedure call, with parameters pushed on to the stack in the normal way.
  2. The client stub packs the parameters into a message and makes a system call to send the message. Packing the parameters is called marshalling.
git credential-osxkeychain erase
host=github.com
protocol=https
@qcam
qcam / jekyll_installation.md
Created July 5, 2014 09:03
Jekyll Installation

##Jekyll Installation

  1. Make a new directory for your blog
mkdir my-awesome-blog
cd my-awesome-blog
  1. Create your .ruby-gemset and .ruby-version
@qcam
qcam / rails-submit-button_18n.md
Created July 3, 2014 09:09
Rails Submit button I18n way

##Rails Submit button I18n way

en:
  helpers:
    submit:
      create: "Make New %{name}%"
      user:
        create: "Register"
 update: "Update Profile"
@qcam
qcam / rails-active_query.md
Created May 23, 2014 05:40
Rails Active Record Query

Rails Active Record Query

INNER JOIN

Category.joins(:posts)

# SELECT categories.* FROM categories INNER JOIN posts ON posts.category_id = categories.id
@qcam
qcam / jquery-on_events.md
Last active August 29, 2015 14:01
jQuery event binding

The markup

<div id="parent">
  <a id="child">Click here please</a>
</div>

Instead of binding event this way this way

@qcam
qcam / capybara-wait_fo_ajax.md
Created May 20, 2014 02:38
Capybara - Wait for ajax to complete

##Capybara - Wait for ajax to complete

def wait_for_ajax
  Timeout.timeout(Capybara.default_wait_time) do
    loop do
      active = page.evaluate_script('jQuery.active')
      break if active == 0
    end
 end
class UrlValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    record.errors[attribute] << (options[:message] || "must be a valid URL") unless url_valid?(value)    
  end

  # a URL may be technically well-formed but may 
  # not actually be valid, so this checks for both.
  def url_valid?(url)
 url = URI.parse(url) rescue false
@qcam
qcam / rails_admin-configuration.md
Created May 16, 2014 11:03
Rails admin field config

Rails Admin field configuration

rails_admin do
  list do
    field :customfield do
      def value
        bindings[:object].your_method
      end
    end
 end
@qcam
qcam / rspec-anomyous_controller.md
Last active August 29, 2015 14:01
How to test anomyous controller with RSpec

In your logged_in_controller.rb

class LoggedInController < ApplicationController
  before_filter :authenticate_user!
end

In your logged_in_controller_spec.rb