Skip to content

Instantly share code, notes, and snippets.

Avatar

Chen Chia Yang Unayung

View GitHub Profile
View webpack.md

How to using jQuery plugins in Rails 6 with webpacker

for example we want using slick-carousel in our application.

  1. yarn add jquery slick-carousel expose-loader
  2. add following lines in app/javascript/packs/application.js
require('slick-carousel')
require('slick-carousel/slick/slick.css')
@Unayung
Unayung / service.rb
Created Jul 21, 2017
General Interface for crawler
View service.rb
class LearningPlatformService
include ColorgyCrawler::DateMixin
def initialize(user)
@user = user
account = user.learning_platform_datum.account
password = Base64.decode64(Base64.decode64(user.learning_platform_datum.password))
lp_klass = LearningPlatform.find!(user.organization_code)
@lp_instance = lp_klass.new(account, password)
@lp_data = @user.learning_platform_datum
@Unayung
Unayung / pchome.rb
Created Jul 13, 2017
pchome 商品資訊抓取
View pchome.rb
require 'capybara'
require 'capybara/dsl'
include Capybara::DSL
Capybara.javascript_driver = :selenium
Capybara.current_driver = :selenium
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox)
end
@Unayung
Unayung / welcome.rb
Last active Jul 6, 2017
welcome.rb 解說
View welcome.rb
name = ARGV[0] #第一個參數
name ||= "" # 如果 name 已經存放東西,就保持原樣,如果 name 沒有存放東西,則將 "" 存放進去
birthday = ARGV[1] #第二個參數
birthday ||= ""
msg = name + " Welcome to X-Program"
msg = msg + " " + Time.now.to_s # .to_s 代表轉換為字串
puts "="* msg.size # .size 計算前面的物件的長度 msg.size 代表計算 msg 這個字串的總長度
@Unayung
Unayung / go.rb
Last active Jul 6, 2017
go.rb 解說
View go.rb
require 'nokogiri'
require 'rest-client'
url = "http://www.appledaily.com.tw/realtimenews/section/sports/" # 一開始的進入點
base_url = "http://www.appledaily.com.tw" # 網站的基本網址
raw_data = RestClient.get(url)
data = Nokogiri::HTML(raw_data.body)
page_links = data.css('nav.page_switch a') # 底下分頁 1,2,3,4,5 的 a 元素
i = 0
View g4h-customize.txt
Feature:
Partners get their own Graphical Interface while using the Golf4Holland System – which means both in frontend and in backend it needs to have the look and feel of the partner. But without any change in layouts of pages.
What must partners be able to do?
• They can invoice their customers
o Collect the money on their own bank account and pay Golf4Holland a fee pp
o G4H collects the money on a separate account and pays Golf4Holland and the partners a fee pp
@Unayung
Unayung / rvm2rbenv.txt
Created Apr 22, 2016 — forked from brentertz/rvm2rbenv.txt
Switch from RVM to RBENV
View rvm2rbenv.txt
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@Unayung
Unayung / nokogiri install
Created Mar 25, 2016
gem install nokogiri issue
View nokogiri install
If previously installed, uninstall the gem:
$ gem uninstall nokogiri
Use Homebrew to install libxml2, libxslt and libiconv:
$ brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:
$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
@Unayung
Unayung / gist:0c13f9c9a5f63e7f5703
Created Nov 24, 2015
Nokogiri 1.6.6.4 installing
View gist:0c13f9c9a5f63e7f5703
gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
View flash_at_same_request.rb
class ClientsController < ApplicationController
def create
@client = Client.new(params[:client])
if @client.save
# ...
else
flash.now[:error] = "Could not save client"
render action: "new"
end
end
You can’t perform that action at this time.