Skip to content

Instantly share code, notes, and snippets.

@whiteleaf7
whiteleaf7 / t.rb
Created February 3, 2017 07:00
プロキシ
def get_toc_source
toc_url = @setting["toc_url"]
return nil unless toc_url
max_retry = 5
toc_source = ""
cookie = @setting["cookie"] || ""
proxy = ["http://YOUR_PROXY_IP:PORT", "user", "password"]
open_uri_options = make_open_uri_options("Cookie" => cookie, allow_redirections: :safe, proxy_http_basic_authentication: proxy)
begin
open(toc_url, open_uri_options) do |toc_fp|
@whiteleaf7
whiteleaf7 / restore.rb
Last active June 18, 2021 23:52
database.yaml 復旧プログラム
require "yaml"
require "ostruct"
require "time"
require "pp"
database = {}
def date_string_to_time(date)
date.is_a?(Time) ? date : Time.parse(date.sub(/[\((].+?[\))]/, "").tr("年月日時分秒@;", "///::: :"))
end
ranking_org = (0..46).to_a
require 'benchmark'
Benchmark.bm 12 do |r|
r.report "top3: range" do
10000000.times do
ranking = ranking_org.dup
top3 = ranking[0..2]
@whiteleaf7
whiteleaf7 / kobo.rb
Created August 6, 2016 18:15
send する時にサイト名でフォルダを分けるように
# -*- coding: utf-8 -*-
#
# Copyright 2013 whiteleaf. All rights reserved.
#
module Device::Kobo
PHYSICAL_SUPPORT = true
VOLUME_NAME = "KOBOeReader"
DOCUMENTS_PATH_LIST = ["/"]
EBOOK_FILE_EXT = ".kepub.epub"
converter "test_convert_numbers.txt" do
def _stash_number_cache(match)
@_number_string_cache ||= {}
index = convert_numbers(@_number_string_cache.size.to_s)
@_number_string_cache[index] = match
"[#数字キャッシュ=#{index}]"
end
def _rebuild_number_cache(io)
var amazon_url_regexp = /(http:\/\/www\.amazon\.(?:com|co\.jp))\/(.+)/;
var shell = new ActiveXObject("WScript.Shell");
function short_amazon_link(text) {
if (!text.split(/%3F|\?/i)[0].match(amazon_url_regexp)) return null;
var matches = [RegExp.$1];
var elements = RegExp.$2.split("/");
for (var i = 0; i < elements.length; i++) {
if (elements[i].match(/^\w+$/)) {
matches.push(elements[i]);
@whiteleaf7
whiteleaf7 / optional_ruby.rb
Created August 7, 2014 01:24
RubyでSwiftのOptionalChainingモドキ
class NilClass
def method_missing(args)
nil
end
end
module Optional
def method_missing(method_name, *args)
if method_name =~ /\?$/
@whiteleaf7
whiteleaf7 / novel.txt.erb
Last active August 29, 2015 13:57
novel.txt.erb
<%# -*- coding: utf-8 -*- -%>
<% Template.target_binary_version(1.0) -%>
<%= toc["title"] %>
<%= toc["author"] %>
<%= cover_chuki %>
[#区切り線]
<% if toc["story"] != "" -%>
あらすじ:
<%= toc["story"] %>
@whiteleaf7
whiteleaf7 / clipboard.rb
Created February 7, 2014 11:49
Rubyでクリップボードの読み込み・書き込み
# -*- coding: utf-8 -*-
#
# Copyright 2014 whiteleaf. All rights reserved.
#
require_relative "winapi"
module Clipboard
class NotOpenClipboardError < StandardError; end