This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #rubyの中からPHPスクリプトを実行するサンプル | |
| def php_exec(script) | |
| IO.popen("php ", "r+") do |php| | |
| php.puts("<?php") | |
| php.puts(script) | |
| php.puts("?>") | |
| php.close_write | |
| php.gets | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #AtCoder Beginner Contest 029 C問題の回答 | |
| #http://abc029.contest.atcoder.jp/tasks/abc029_c | |
| #問題文 | |
| #あなたはスーパーハッカーです。高橋君を攻撃対象に定めたあなたは、 | |
| #高橋君のパソコンのパスワードに関して次の事実を突き止めました。 | |
| # | |
| # 長さは N 文字である。 | |
| # a, b, c 以外の文字は含まれない。 | |
| #高橋君のパソコンのパスワードの候補として考えられる文字列をすべて列挙してしまいましょう。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #AtCoder Beginner Contest 029 D問題の回答 | |
| #http://abc029.contest.atcoder.jp/tasks/abc029_d | |
| #問題文 | |
| #高橋君は 1 以上 N 以下のすべての整数を十進表記で一回ずつ紙に書きました。 | |
| #この作業で、高橋君は 1 という数字を何個書いたでしょうか。 | |
| #時間がかかるのはわかっているので最初から部分点狙い。 | |
| max = gets | |
| count = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| == License == | |
| Public Domain | |
| =end | |
| require 'webrick' | |
| require 'webrick/httpproxy' | |
| require 'uri' | |
| require 'yaml' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //Descritptionにカテゴリ名・カスタムフィールドの内容を入れる | |
| add_filter('metadescriptionCustom', 'customize_description'); | |
| //変数 $metadesctiption には元々のdescriptionが入ってくる | |
| function customize_description($metadescription) { | |
| global $post; | |
| //今回は特定の投稿タイプの個別ページのみ | |
| if (get_post_type($post) != "sitelist" || !is_single() ) { | |
| return $metadescription; //何もしない | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A | |
| def set_class_variable | |
| @@a = class_variable #サブクラスで定義したメソッドを呼び出すことによってクラス変数の値をセットする | |
| end | |
| end | |
| class B < A | |
| def class_variable | |
| "class B" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| #rubyのプロセスを立ち上げて自分はすぐに終了するシェルスクリプト。 | |
| #Macの場合、ファイル名の拡張子を*.commandにしておくとログイン時やダブルクリック時に実行できる | |
| APP_HOME=`dirname $0` #スクリプトのパスを取得する | |
| cd $APP_HOME #rubyのスクリプトが存在するパスへ移動 | |
| bundle exec ruby daemon.rb >> debug.log & #最初から入っているrubyが動くはず。 bundlerは前もって自分で入れる必要がある。 | |
| killall Terminal #これがないとスクリプトが終了してもターミナルが開きっぱなしになる。他にターミナルが立ち上がっている場合はヤバイ。 | |
| #最後のkillallはやめて、ターミナルの環境設定からシェルの終了時にウインドウを閉じる設定をしたほうがいいかもしれない。 | |
| # http://www.monochrome-photo.info/?p=9251 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #sendmailコマンドで添付ファイル付きメールを送信。 | |
| #ruby1.8.5で最近のメールライブラリが動かなかったので。 | |
| require "base64" | |
| def mail(to, attach_file) | |
| now = Time.now | |
| filename = "#{now.strftime("%Y%m%d-%H%M%S")}.csv" | |
| mail_boundary = now.strftime("%Y%m%d%H%M%S") | |
| mail = <<EOS | |
| To: #{mail_address} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #jpegtranとgifsicleではワイルドカードが使えないのでrubyでファイル名を繰り返し渡してやる。 | |
| #JPEG | |
| ruby -e 'ARGV.each{|file| `jpegtran -copy none -optimize -outfile #{file} #{file}`}' *.jpg | |
| #GIF | |
| ruby -e 'ARGV.each{|file| `gifsicle -O2 -o #{file} #{file}`}' *.gif | |
| #PNG | |
| optipng *.png |