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 / 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 / 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
require 'oauth'
require 'oauth2'
class ContactImporter
def initialize(importer)
@importer = importer
end
def authorize_url
case @importer
@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;
@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));
}
# 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 / 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
@vinhnglx
vinhnglx / example_nokogiri_scraping.rb
Created September 20, 2015 04:17
example_nokogiri_scraping.rb
require 'open-uri'
require 'nokogiri'
require 'csv'
# Store URL to be scraped
url = "https://deliveroo.co.uk/restaurants/london/maida-vale?postcode=W92DE&time=1800&day=today"
# Parse the page with Nokogiri
page = Nokogiri::HTML(open(url))
# Display output onto the screen
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
context "GET index" do
#context "POST create" do
#context "GET show" do
#context "PATCH update" do (or PUT update)
#context "DELETE destroy" do
#context "GET new" do
@vinhnglx
vinhnglx / omniauth_macros.rb
Created October 6, 2015 01:18 — forked from kinopyo/omniauth_macros.rb
Integration test with Omniauth. This example is using twitter, and assume you've installed rspec and capybara. Official document is here: https://github.com/intridea/omniauth/wiki/Integration-Testing
# in spec/support/omniauth_macros.rb
module OmniauthMacros
def mock_auth_hash
# The mock_auth configuration allows you to set per-provider (or default)
# authentication hashes to return during integration testing.
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
'uid' => '123545',
'user_info' => {
'name' => 'mockuser',