Skip to content

Instantly share code, notes, and snippets.

Avatar

Anndo Ko anndoko

View GitHub Profile
View application.js
$(document).on('scroll', function () {
/*===== Welcome#index - 首頁導航列變化 =====*/
if ($(this).scrollTop() > 125) {
$('#navbar').addClass('show_bgcolor')
} else {
$('#navbar').removeClass('show_bgcolor')
}
/*===== Welcome#index - 回到頁面頂端 =====*/
if ($(this).scrollTop() > 2500) {
View admin#show.html.erb
<!-- 商品圖片 -->
<div class="row">
<% if @product_images.present? %>
<!-- 第一張圖為 medium 尺寸大圖 -->
<div class="col-md-12">
<%= image_tag(@product_images.first.image.thumb.url, class: 'main-image') %>
</div>
<% @product_images.each_with_index do |p| %>
<!-- 顯示所有商品圖片 - other 尺寸小圖 -->
<div class="col-md-2 col-sm-4 col-xs-6 image-box">
View products#index.html.erb
<!--=== 商品列表迴圈示範代碼,利用迴圈把 @products 的內容印出來 ===-->
<div class='row'>
<!--=== 迴圈開始 ===-->
<% @products.each_with_index do |product, index| %>
<!-- 每一個產品 Grid 佔比:xs 尺寸 12/12,sm 尺寸 4/12,md 尺寸 3/12 -->
<div class='col-xs-12 col-sm-4 col-md-3 product-content'>
<!-- 點圖片,連結到該產品 -->
<%= link_to product_path(product) do %>
<!-- 商品圖片 -->
@anndoko
anndoko / product.rb
Created Jun 9, 2017
隨機推薦 3 樣商品
View product.rb
# app/models/product.rb
# scope,隨機選 3 項商品
scope :random3, -> { limit(3).order('RANDOM()') }
View index_sample.html.erb
<div class="product-index">
<div class="container">
<!-- 左側:產品列表,佔 8/12 -->
<section class="col-md-8 main">
<% @prodcuts.products.each_with_index do |product, index| %>
<!-- 把產品的內容印出來 -->
<div class="row">
</div>
<% end %>
View form.html.erb
<!-- Radio Button UI (Bootstrap) -->
<div class="btn-group" data-toggle="buttons">
<% Event::STATUS.each do |status| %>
<label class="btn btn-default <%= (status == f.object.status)? 'active' : '' %>">
<%= f.radio_button :status, status %>
<%= t(status, :scope => "event.status") %>
</label>
<% end %>
</div>
View same_code.py
# step 3
def get_from_itunes(search_name, search_type):
url_parameters = {}
url_parameters["format"] = "json"
url_parameters["term"] = search_name
url_parameters["entity"] = search_type
base_url = "https://itunes.apple.com/search"
itunes_result_data = requests.get(url = base_url, params = url_parameters).json()
View magic_ball.py
# prompt the user for input
user_question = input("Please enter your question:")
# check if quesion mark is included:
user_q_lst = list(user_question)
if user_q_lst[-1] != "?":
user_question += "?" # if not, add "?" to the string
# create the list of standard Magic 8 Ball answers
magic_ans = [
View umsicrawl_cache.py
from bs4 import BeautifulSoup
import requests
import json
# Caching
CACHE_FNAME = 'cache.json'
try:
cache_file = open(CACHE_FNAME, 'r')
cache_contents = cache_file.read()
View Q8.py
statement8 = "SELECT * "
statement8 += "FROM [Order]"
statement8 += "LIMIT 1;"
print("\n" + "=" * 30)
print("Columns in the Order Table\n")
columns_in_order_table = cur.execute(statement8)
for column in columns_in_order_table.description:
print(column[0])