This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby -w | |
# coding:utf-8 | |
require 'fileutils' | |
Dir.glob('./*.txt').each do |f| | |
FileUtils.mv f, "#{File.basename(f,'.*')}.md" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby -w | |
# coding:utf-8 | |
require 'net/http' | |
require 'uri' | |
#str = 'http://htmljs.b0.upaiyun.com/uploads/1460943735482-f24c0e5ca2f9d61b48cdd7c215226849.jpg!bac' | |
def downloadurl(str) | |
uri = URI.parse(str) | |
filename = str.split('/')[-1].chomp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby -w | |
# author:beepony | |
# description: md5 digest string | |
require 'digest' | |
def md5(string) | |
Digest::MD5.hexdigest(string.encode('utf-8')) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby -w | |
# encode and decode use ruby base64 lib | |
# use strict model to avoid "\n" problem every 76 characteres | |
require 'base64' | |
decode_string = Base64.strict_encode64(string) | |
encode_string = Base64.strict_decode64(string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
# 随机生成 7 位数字的 | |
string = ('a'..'z').to_a.shuffle[0..7].join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby -w | |
# 使用 net/http 发送 post 请求,带上自定义的 header | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
uri = URI.parse("http://xxx.com/foo/bar") | |
# 设置请求头 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%a - The abbreviated weekday name (Sun) 缩写的星期 | |
%A - The full weekday name (Sunday) | |
%b - The abbreviated month name (Jan) 缩写的月份 | |
%B - The full month name (January) | |
%d - Day of the month (01..31) | |
%e - Day of the month (1..31) | |
%H - Hour of the day, 24-hour clock (00..23) | |
%I - Hour of the day, 12-hour clock (01..12) | |
%l - Hour of the day () | |
%j - Day of the year (001..366) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
image = Net::HTTP.get_response(URI.parse("http://www.site.com/file.png")).body | |
file = File.open("path-to-file.txt", "rb") | |
contents = file.read |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ftp' | |
CONTENT_SERVER_DOMAIN_NAME = "one-of-the-ftp-server.thought-sauce.com.hk" | |
CONTENT_SERVER_FTP_LOGIN = "saucy-ftp-server-login" | |
CONTENT_SERVER_FTP_PASSWORD = "saucy-ftp-server-password" | |
# LOGIN and LIST available files at default home directory | |
Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_FTP_LOGIN, CONTENT_SERVER_FTP_PASSWORD) do |ftp| | |
files = ftp.list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ftp' | |
def scan(ftp, dir) | |
ftp.chdir(dir) | |
puts ftp.pwd + "/." | |
entries = ftp.list('*') | |
entries.each do |entry| | |
if entry.split(/\s+/)[0][0,1] == "d" then | |
scan(ftp, entry.split.last) | |
else |
OlderNewer