Skip to content

Instantly share code, notes, and snippets.

View vinhnglx's full-sized avatar
👓
Code is fun

Vincent Nguyen vinhnglx

👓
Code is fun
View GitHub Profile
@vinhnglx
vinhnglx / example.rb
Created December 27, 2014 08:37
Class method inside class
# First
class Example
def hello
puts 'hello'
end
def vinh
puts 'vinh'
end
end
# is_printed? la 1 cai method, dau hoi la 1 kieu naming convention. Method return true or false se co dau ?
# con dau ! la phu dinh
while !document.is_printed?
document.print_next_page
end
@vinhnglx
vinhnglx / applications.scss
Created October 13, 2014 16:07
Compass filter image
@import "compass/css3/filter";
.filtered {
@include filter(grayscale(50%));
@include filter(blur(10px));
}
@vinhnglx
vinhnglx / application.scss
Created October 13, 2014 15:58
Compass CSS Regions
@import "compass/css3";
.main_content {
@include flow-into(target);
}
.regions div {
@include flow-from(target);
width: 150px;
height: 190px;
require 'oauth'
require 'oauth2'
class ContactImporter
def initialize(importer)
@importer = importer
end
def authorize_url
case @importer
@vinhnglx
vinhnglx / anonymousllama.rb
Created September 18, 2014 00:17
AnonymousLlama
for i in 1..100 do
if i % 3 == 0
puts 'Anonymous'
elsif i % 5 == 0
puts 'Llama'
end
if (i % 3 == 0 && i % 5 == 0)
puts 'AnonymousLlama'
end
@vinhnglx
vinhnglx / file0.rb
Created September 17, 2014 15:27
Easily switch user without login, logout ref: http://qiita.com/vinhnguyenleasnet/items/1d5061b443173da967bc
gem "switch_user
@vinhnglx
vinhnglx / contact.html.erb
Last active August 29, 2015 14:06
Using Omnicontacts to get mail contacts from Google ref: http://qiita.com/vinhnguyenleasnet/items/53ade9f730d21a7a84d4
<% unless @contacts.nil?%>
<% @contacts.each do |c|%>
<ul>
<li><%= c[:name]%> : <%= c[:email]%></li>
</ul>
<%end%>
<%end%>
@vinhnglx
vinhnglx / file0.rb
Last active August 29, 2015 14:06
Using Metaprogramming to refactor code ref: http://qiita.com/vinhnguyenleasnet/items/3c96930a7b48786e81cf
class User < ActiveRecord::Base
validate_inclusion_of :activation_state, :in => ["pending", "active"]
def self.pending_users
find :all, :conditions => {:activation_state => 'pending'}
end
def self.active_users
find :all, :conditions => {:activation_state => 'active'}
end
class AddNameToUser < ActiveRecord::Migration
def self.up
add_column :users, :name, :string
User.reset_column_information
User.find(:all).each do |user|
user.name = user.first_name + ' ' + user.last_name
end
remove_column :users, :first_name
remove_column :users, :last_name
end