Skip to content

Instantly share code, notes, and snippets.

View roger35972134's full-sized avatar

Roger Wang roger35972134

View GitHub Profile
class CurrencyController < ApplicationController
require 'line/bot'
def client
@client ||= Line::Bot::Client.new { |config|
config.channel_secret = ENV["LINE_CHANNEL_SECRET"] # Your Channel secret
config.channel_token = ENV["LINE_CHANNEL_TOKEN"] # Your Channel token
}
end
class Currency < ActiveRecord::Base
require 'open-uri'
def self.get_currency
begin
books = Nokogiri::HTML(open("https://www.coingecko.com/en"))
name = []
abbreviation = []
rate = []
exchange = []
def length_of_longest_substring(s)
max = 0
start_index = -1
char_to_index_map = {}
s.chars.each_with_index do |c, i|
if current_index = char_to_index_map[c] and current_index > start_index # if current_index != nil
start_index = current_index
end
# @param {String} s
# @return {Integer}
def length_of_longest_substring(s)
max = 0
for i in 0..s.length-1
check = Array.new(256, false)
for j in i..s.length-1
index = s[j].ord
if check[index] == false
@roger35972134
roger35972134 / Leetcode_3:time_limit.rb
Created October 11, 2017 06:00
Leetcode 3. Longest Substring Without Repeating Characters, but it failed by Submission Result: Time Limit Exceeded
# @param {String} s
# @return {Integer}
# ----------time limit-------------
def length_of_longest_substring(s)
longest_length = 0
for i in 0..s.length-1
check = []
for j in i..s.length-1
unless check.include? s[j]
check.push s[j]
@roger35972134
roger35972134 / udn_news_crawler.rb
Last active September 27, 2017 07:41
crawler preparation for NEWS analysis
require 'nokogiri'
require 'open-uri'
# Let's try to fetch and parse HTML document
books = Nokogiri::HTML(open('https://udn.com/rank/pv/2/0/1'))
news = []
i = 0
# Tetromino for Idiots
# By Al Sweigart [email protected]
# http://inventwithpython.com/pygame
# Released under a "Simplified BSD" license
import random, time, pygame, sys
from pygame.locals import *
偵數 = 25
視窗寬度 = 640
from matplotlib import pyplot
from collections import namedtuple
from pprint import pprint as pp
from math import floor
#由於有點摸不著頭緒,所以參考了一下同學的程式碼,我下次會更多自己的想法
Stem = namedtuple('Stem', 'data, leafdigits')
data0 = Stem((4285,564,1278,205,3920,
2066,604,209,602,1379,
2584,14,349,3770,99,
import itertools
def main():
print(__doc__)
排假(1, True)
排假(2, True)
排假(3)
排假(4)
@roger35972134
roger35972134 / python_hw2
Created May 11, 2015 16:45
第二次python作業
def main():
列出巴斯卡三角形()
畫出二項分佈()
畫出巴松分佈()
def 列出巴斯卡三角形():
Z=[[bCoef(n,k) for k in range(n+1)] for n in range(20)]
for z in Z: print(z)