Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
snipsnipsnip / pdf2png.rb
Last active March 5, 2017 11:52
pdf2png: runs 'mutool extract' and renumbers
#!/usr/bin/ruby
# * coding: utf-8 *
class PDFExtract
def self.main
ARGV.each {|a| new.extract a }
end
def extract(pdf)
images = parse_info(`mutool info #{pdf}`)
@snipsnipsnip
snipsnipsnip / pingport.rb
Last active January 31, 2017 12:09
pingport.rb
#!/usr/bin/env ruby
# coding: utf-8
require 'socket'
ARGV.size == 2 or abort "usage: #$0 hostname port"
host, port = ARGV
sec = 1
@snipsnipsnip
snipsnipsnip / dummy_ssl_server.rb
Created May 5, 2016 10:27
dummy_ssl_server.rb
require 'socket'
require 'openssl'
def wrap(server)
key = OpenSSL::PKey::RSA.generate(2048)
cert = OpenSSL::X509::Certificate.new
cert.issuer = cert.subject = OpenSSL::X509::Name.new([['CN', 'localhost']])
cert.public_key = key.public_key
cert.not_before = Time.now
cert.not_after = cert.not_before + 60 * 60
@snipsnipsnip
snipsnipsnip / dll.rb
Last active March 19, 2016 03:07
dll.rb: dumpbin/undname wrapper
require 'tempfile'
class DLL
include Enumerable
attr_reader :path
def initialize(path)
@path = path
end
@snipsnipsnip
snipsnipsnip / hosts.txt
Created March 5, 2016 12:44
add these lines to hosts to remove skype ads
127.0.0.1 *.2mdn.net
127.0.0.1 *.adnxs.com
127.0.0.1 *.adtech.de
127.0.0.1 *.atdmt.com
127.0.0.1 *.flashtalking.com
127.0.0.1 *.msads.net
127.0.0.1 *.msecn.net
127.0.0.1 *.msn.com
127.0.0.1 *.serving-sys.com
127.0.0.1 *.doubleclick.net
@snipsnipsnip
snipsnipsnip / prepare-cacert-pem.rb
Last active March 1, 2016 13:39
prepare-cacert-pem.rb
require 'fileutils'
require 'openssl'
require 'open-uri'
CACERT_URI = 'https://curl.haxx.se/ca/cacert.pem'
def main
if force = ARGV.include?('-f') || ARGV.include?('--force')
u = FileUtils::Verbose
else
@snipsnipsnip
snipsnipsnip / parse_yaml_with_pretty_error.rb
Created February 26, 2016 15:05
def parse_yaml_with_pretty_error(str)
def parse_yaml_with_pretty_error(str)
YAML.load(str)
rescue Psych::SyntaxError => e
range = e.line - 5..e.line + 5
str.lines[range].zip(range) {|s, n| warn "#{n + 1}: #{s}#{%_#{' ' * (e.column - 1)}^_ if n + 1 == e.line}" }
raise
end
@snipsnipsnip
snipsnipsnip / eval-ruby.js
Last active December 26, 2015 11:29
mery macro: eval-ruby.js
if (document.selection.IsEmpty) {
document.selection.EndOfLine(false, mePosLogical)
document.selection.StartOfLine(true, mePosLogical)
}
var shell = new ActiveXObject('WScript.Shell')
shell.CurrentDirectory = document.Path || shell.SpecialFolders("Desktop")
var exec = shell.Exec('rubyw.exe -rtimeout -e "STDERR.reopen STDOUT; $0 = STDIN.gets.rstrip; print begin; Timeout.timeout(2) { eval($_ = STDIN.read) }; rescue Exception; %_#<#{$!.class}:#{$!.message}>_ end"')
exec.StdIn.WriteLine(document.FullName)
@snipsnipsnip
snipsnipsnip / indented_forest.rb
Last active December 13, 2015 08:36
継承つきネスト箇条書き
require 'yaml'
# StringForest = nil | (String, StringForest)[]
# String -> StringForest
def parse_indented_forest(str)
str = str.gsub(/^( *)([^": \n][^":\n]*)$/, '\1"\2":')
handle_includes YAML.load(str)
end
def handle_includes(tree)
@snipsnipsnip
snipsnipsnip / tom.rb
Created November 26, 2015 11:36
tom.rb: primitive JSP lint
# coding: utf-8
#
# tom: JSPのタグ開閉の対応チェッカ
# MIT license, @snipsnipsnip
#
=begin
JSPの文法は普通のHTMLと違ってかなりゆるい。