Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
hyuki0000 / a.rb
Created February 27, 2016 09:51
一瞬はまった。
def foo(id)
s = id.to_s
s.sub!(/^(\d\d\d\d)$/, '\1年')
s
end
id = '2016'
foo(id)
puts id #=> 2016年
@hyuki0000
hyuki0000 / make-landing-page-for-note6.erb
Last active February 14, 2016 05:41
でんでんランディングページをerbで書いたもの。ただし『数学ガールの秘密ノート/ベクトルの真実』のランディングページ専用になっている。詳しくは、 https://snap.textfile.org/20160214142505/ を参照のこと。
<%
COLOR_PRIMARY = '#ab5637'
TWITTER = '@hyuki'
TWITTER_URL = 'http://twitter.com/hyuki'
URL = 'http://note6.hyuki.net/'
TITLE = '数学ガールの秘密ノート/ベクトルの真実'
BACKGROUND_IMAGE = 'http://static.tumblr.com/91187c5df2205978c2937c64fa62d5bc/qcurvlw/K4pnwia5u/tumblr_static_ebhmjmagw5k48cw8oogkow8o4_2048_v2.png'
SHORTCUT_ICON = 'http://33.media.tumblr.com/avatar_f70f97f2c814_128.png'
SHORTCUT_ICON_PRECOMPOSED = 'http://33.media.tumblr.com/avatar_f70f97f2c814_128.png'
BOOK_COLLECTION_TITLE = '数学ガールの秘密ノート'
@hyuki0000
hyuki0000 / replace_http_with_https.rb
Last active February 7, 2016 02:39
大量のmarkdownファイルの http://img.textfile.org/https://img.textfile.org/ に書き換えるため作ったもの。
#!/usr/bin/env ruby
# encoding: utf-8
Dir.glob("source/*.md").each do |md|
open("#{md}.txt", "w") do |wf|
open(md) do |rf|
rf.readlines.each do |line|
if line.match(%r(http://img\.textfile\.org/))
line.gsub!(%r(http://img\.textfile\.org/), "https://img.textfile.org/")
end
@hyuki0000
hyuki0000 / media-tweet.rb
Created October 18, 2015 12:06
複数画像付きでツイートするRubyスクリプト(呼び出すたびに違うツイート用)
#!/usr/bin/env ruby
require 'twitter'
CLIENT = Twitter::REST::Client.new do |config|
config.consumer_key = "XXXXXXXXXXXXXXXXXXXXXXXXX"
config.consumer_secret = "ssssssssssssssssssssssssssssssssssssssssssssssssss"
config.access_token = "0000000-tttttttttttttttttttttttttttttttttttttttttt"
config.access_token_secret = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
end
\documentclass[a5paper,10pt]{jsbook}
\usepackage[dvipdfmx]{color}
\usepackage[dvipdfmx]{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amscd}
\usepackage{euler}
\usepackage{okumacro}
\usepackage{colortbl}
\usepackage{otf}
@hyuki0000
hyuki0000 / gist.markdown
Last active August 29, 2015 14:24
gistを使うとコマンドラインからgistを更新できる。

gist: Create & update your gists via the command line.

Install.

$ brew install gist
$ gist --help

Login.

@hyuki0000
hyuki0000 / not-used-fig.rb
Created June 21, 2015 12:46
Which figure files are not used during LaTeXing?
#! /usr/bin/ruby
require "fileutils"
if ARGV.length != 2
puts <<-"EOD"
Which figure files are not used during LaTeXing?
Usage: ruby not-used-fig.rb LOGDIR FIGDIR
Example: ruby not-used-fig.rb . fig
LOGDIR contains *.log files.
@hyuki0000
hyuki0000 / imeoff.rb
Last active April 19, 2016 04:30
自動的にIMEをオフにするスクリプト(実際に実行するのは10秒に一回)。
#!/bin/ruby
# Based on http://blog.teapla.net/2015/05/5444
TOUCH_FILE = ENV["HOME"] + "/.imeoff"
INTERVAL_SEC = 10
if not File.exists?(TOUCH_FILE) or Time.now - File.ctime(TOUCH_FILE) > INTERVAL_SEC
system("osascript -e 'tell application \"System Events\" to key code 102'")
system("touch #{TOUCH_FILE}")
end
@hyuki0000
hyuki0000 / note-prevs.rb
Last active September 13, 2019 04:05
note-prevs - note.mu の指定されたURLからprevリンクをたどり、各ページのタイトルとURLを表示するRubyスクリプト。
#!/usr/bin/env ruby
if ARGV.length != 1
puts "Usage: ruby note-prevs.rb https://note.mu/USERNAME/n/NOTEID"
puts "Example: ruby note-prevs.rb https://note.mu/hyuki/n/n220bad7464fb"
puts "This program visits given user's pages via prev-link and puts their titles and urls."
abort
end
# cf. https://note.mu/wadako/n/n01733b19bc9c