Skip to content

Instantly share code, notes, and snippets.

@macks
macks / cedec2017-session-scraper.rb
Created August 25, 2017 08:23
CEDEC 2017 のセッション情報を取得する
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
require 'json'
sessions = []
%w(
http://cedec.cesa.or.jp/2017/session/schedule_0830/
@macks
macks / gacha.rb
Last active December 27, 2016 15:25
ガチャで複数の当たりを引く確率
def combination(n, r)
factorial(n) / factorial(r) / factorial(n - r)
end
def permutation(n, r)
factorial(n) / factorial(n - r)
end
$factorial = { 0 => 1 }
@macks
macks / gist:eff94050f89d622a2382
Created March 25, 2016 20:10
letsencrypt sample
$ sudo letsencrypt certonly --staging --verbose --email name@example.com -d example.com -w /home/www/example.com/htdocs
@macks
macks / gist:9951996989add729e839
Last active August 29, 2015 14:27
Tiarra IRC Proxy: Avoid warnings for Slack IRC gateway
--- a/main/IrcIO/Server.pm
+++ b/main/IrcIO/Server.pm
@@ -829,6 +829,9 @@ sub _MODE {
};
for (;$mode_char_pos < $n_params;$mode_char_pos += $mode_param_offset + 1) {
+ if (substr($msg->param($mode_char_pos), 0, 1) eq ' ') {
+ next;
+ }
$mode_param_offset = 0; # これは毎回リセットする。
diff -ruN bind-9.9.7-P1/lib/dns/tkey.c bind-9.9.7-P2/lib/dns/tkey.c
--- bind-9.9.7-P1/lib/dns/tkey.c 2015-06-18 07:48:03.000000000 +0900
+++ bind-9.9.7-P2/lib/dns/tkey.c 2015-07-15 08:50:22.000000000 +0900
@@ -650,6 +650,7 @@
* Try the answer section, since that's where Win2000
* puts it.
*/
+ name = NULL;
if (dns_message_findname(msg, DNS_SECTION_ANSWER, qname,
dns_rdatatype_tkey, 0, &name,
@macks
macks / gist:29836d78bd61bd91191e
Created April 28, 2015 06:07
Selenium::WebDrvier::Chrome
@download_dir = File.join(Dir.pwd, 'download')
FileUtils.mkdir_p(@download_dir)
prefs = {
download: {
prompt_for_download: false,
default_directory: @download_dir,
}
}
Selenium::WebDriver::Chrome.driver_path = File.join(Dir.pwd, 'chromedriver')
require 'webrick'
require 'webrick/httpproxy'
require 'optparse'
require 'fileutils'
opts = {
port: 8080,
outdir: '.',
}
optparse = OptionParser.new("USAGE: #{$0} [OPTIONS]", 20)
@macks
macks / gist:6249109
Last active December 21, 2015 04:28
Bug fix for Tiarra IRC Proxy. Stuck in a name resolver when addresses are inconsistent.
--- a/main/Tiarra/Resolver.pm
+++ b/main/Tiarra/Resolver.pm
@@ -269,6 +269,8 @@ sub _paranoid_stage2 {
if ($entry->answer_status eq $entry->ANSWER_OK) {
if (grep { $data eq $_ } @{$entry->answer_data}) {
$closure->(1, $entry->query_data, $entry);
+ } else {
+ $closure->(0, undef, $entry);
}
} else {
@macks
macks / update-route53.sh
Created June 6, 2012 17:42
Update Route53
#!/bin/bash
cli53=$HOME/bin/cli53
. $HOME/.ec2/env
ec2-describe-instances | \
perl -lane '/^INSTANCE/ and $name = $F[3]; /^TAG/ and $F[3] eq "Name" and print "$F[4] CNAME $name"' | \
xargs -n 3 -r $cli53 rrcreate aws.example.com --ttl 60 --replace
@macks
macks / iTunes_win32ole.rb
Created December 29, 2011 22:57
Controll iTunes from Ruby script using WIN32OLE
require 'win32ole'
app = WIN32OLE.new('iTunes.Application')
# p app.ole_obj_help
# p app.ole_methods
tracks = app.LibraryPlaylist.Tracks
puts "Num of tracks: #{tracks.Count}"
tracks.each do |track|
%w(Artist Name Album).each do |name|