Skip to content

Instantly share code, notes, and snippets.

@maraigue
maraigue / classname2instance.rb
Created May 15, 2011 09:26
Rubyのクラス名を文字列で与えて(例:"Hoge::Piyo")そのクラスのインスタンスを生成する方法
#!/usr/bin/ruby
#
# = 元ネタ
#
# Kawaz - Pythonで文字列からクラスインスタンスを生成したりメソッドを呼ぶ方法
#
# http://www.kawaz.org/blogs/miiojp/2011/05/15/106/
#
# 上記ページでは、Pythonで "hogehoge.hogenoho.HogeClass" のような文字列に
@jjb
jjb / gist:996510
Created May 28, 2011 02:00
How to set the certificate file for Net::HTTP library-wide

In my previous post I described how to securely acquire the Mozilla list of root certificates and convert them to a form usable by curl and various libraries which don't ship with them.

Next, I want to point Net:HTTP at this file library-wide, so that it is used by all invocations of methods accessing https resources (in particular, Kernel#open, which in ruby 1.8.7 does not have a ca_file option and is therefore unusable with https). I hunted around the ruby standard library for a couple hours and came up with this:

require 'open-uri'
require 'net/https'

module Net
 class HTTP
@kinopyo
kinopyo / nokogiri_https.rb
Created June 21, 2011 08:58
nokogiri parse https url
require 'net/https'
require 'nokogiri'
url = "https://example.com"
url = URI.parse( url )
http = Net::HTTP.new( url.host, url.port )
http.use_ssl = true if url.port == 443
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if url.port == 443
path = url.path
path += "?" + url.query unless url.query.nil?
@yuki-teraoka
yuki-teraoka / enumerator_lazy_ruby19.rb
Created December 4, 2012 06:55
Enumerator::Lazy for ruby 1.9
module Enumerable
def lazy
enum = self
Enumerator::Lazy.new(self).tap do |obj|
obj.instance_variable_set(:@enum , enum)
obj.instance_variable_set(:@method, false)
obj.instance_variable_set(:@args , [])
end
end
end
@tehprofessor
tehprofessor / watir_phantomjs_user_agent_settings.rb
Created May 1, 2013 18:28
Configuring Watir to use a custom user agent with the PhantomJS driver. The user agent gem has been deprecated, and this functionality is not documented anywhere (obvious).
require 'watir-webdriver'
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36")
driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities
browser = ::Watir::Browser.new driver
# Quick test to make sure it's set
browser.goto 'http://www.useragentstring.com/'
browser.textarea(:id => "uas_textfeld").value
#!/bin/bash
## NHKのネット配信サービスであるらじる★らじる。
# 従来は https://gist.github.com/riocampos/5656450 のように rtmpdump を使う必要がありましたが、
# 2017年9月から m3u8 による配信へ変更になったようです。m3u8 なので10秒単位での録音になります。
## 録音コマンド(m4a)
#ffmpeg -i M3U8URL -c copy outputfilename.m4a
# ファイルサイズ的に m4a が最も小さくなる