12
anonymous No title
Ruby
@REM jww 外部変形
@REM 円外消去.BAT
@echo off
REM #jww
REM #cd
REM #ht10
REM #ht20
REM #ht40
REM #zz
goto %1
REM #hm【円外消去】 |円外消去|等倍複写|2倍複写|N倍複写|回転複写|
REM #:1
REM #h2
REM #hc  【円外消去】処理範囲を指定してください
REM #g1
REM #bz
REM #9ci 【円外消去】円を指示
REM #e
REM #:2
REM #h2
REM #hc  【等倍複写】処理範囲を指定してください
REM #g1
REM #bz
REM #9ci 【等倍複写】円を指示
REM #0%d 【等倍複写】複写先指示
REM #e
REM #:3
REM #h2
REM #hc  【2倍複写】処理範囲を指定してください
REM #g1
REM #bz
REM #9ci 【2倍複写】円を指示
REM #0%d 【2倍複写】複写先指示
REM #e
REM #:4
REM #h2
REM #hc  【N倍複写】処理範囲を指定してください
REM #g1
REM #bz
REM #9ci 【N倍複写】円を指示
REM #0%d 【N倍複写】複写先指示
REM #c   【N倍複写】倍率指定(無指定:1) : /_N
REM #e
REM #:5
REM #h2
REM #hc  【回転複写】処理範囲を指定してください
REM #g1
REM #bz
REM #9ci 【回転複写】円を指示
REM #0%d 【回転複写】複写先指示
REM #c   【回転複写】倍率指定(無指定:1) : /_N
REM #e

:1
:2
:4
copy jwc_temp.txt jwc_bak.txt
rubyw -x %~f0 %1 %2
GOTO  END
:3
copy jwc_temp.txt jwc_bak.txt
rubyw -x %~f0 %1 N2
GOTO  END
:5
copy jwc_temp.txt jwc_bak.txt
rubyw -x %~f0 -%1 %2
GOTO  END

【円外消去】指定した円の外側を消去
【等倍複写】指定した円の外側を消去して複写
【2倍複写】倍率2倍
【N倍複写】倍率N倍
【回転複写】意味はないけどランダムに回転させてみる

#! ruby
# encoding: SJIS

# 座標値を取り込む際に円の中心からの相対座標に直す
# 座標値を出力する際
# 【円外消去】では座標を元に戻す
# 他は行列を使って倍率をかけたり回転させたり

include Math
require 'matrix'

$stdout=open("jwc_temp.txt","w")
$stderr=open("tmp_err.txt","w")

def kouten(a,c,b,d) #外積を使って二線(ab,cd)の交点を求める
  a=Vector.elements(a.to_a+[0])
  b=Vector.elements(b.to_a+[0])
  c=Vector.elements(c.to_a+[0])
  d=Vector.elements(d.to_a+[0])
  cp1=(d-b).cross(b-a)[2]
  cp2=(d-b).cross(c-b)[2]
  k=cp1/(cp1+cp2)
  p=k*(c-a)+a
  p=Vector.elements(p.to_a[0..1])
end

opt=ARGV[0].to_i #1:【円外消去】
jwc=open("jwc_bak.txt").read
n=ARGV.grep(/^N/)[0].to_s.gsub(/^N/,"").to_f
n=1.0 if n==0
mx=Matrix[[n,0],[0,n]]
rd=rand(0.0..360.0)
mk=Matrix[[cos(rd*PI/180.0),-sin(rd*PI/180.0)],
  [sin(rd*PI/180.0),cos(rd*PI/180.0)]] #回転用行列
vo=Vector[0,0]

cir=jwc.match(/hhp9ci\nci (-?[\d.]+) (-?[\d.]+) (-?[\d.]+)/m).
  to_a.map{|e| e.to_f}[1..3]
v0=Vector.elements(cir[0..1])
r1=cir[2]

jwc.split("\n").each{|jw|
  if jw.match(/^hq/)
    puts "hd" if opt==1
  elsif jw.match(/^pt (.*)/) #点の処理
    vp=Vector.elements($1.split(" ").map{|f| f.to_f})
    vp=vp-v0
    if vp.r<r1
      puts "pt "+(vp+v0).to_a.join(" ")      if opt==1
      puts "pt "+(mx*vp).to_a.join(" ")      if opt>=2
      puts "pt "+(mk*mx*vp).to_a.join(" ")  if opt==-5
    end
  elsif jw.match(/^( -?[\d.]+){4}/) #線の処理
    vs,ve=$&.split(" ").map{|e| e.to_f}.
      each_slice(2).map{|e| Vector.elements(e)}
    vs,ve=vs-v0,ve-v0
    vs,ve=ve,vs if vs.r>ve.r
    vb=Matrix[[0,-1],[1,0]]*(ve-vs) #90°回転
    vh=kouten(vo,vb,vs,ve) #円の中心から線への垂点
    if vh.r<r1
      vp=(ve-vs)*sqrt(r1**2-(vh.r)**2)/(ve-vs).r+vh
      vq=(vs-ve)*sqrt(r1**2-(vh.r)**2)/(ve-vs).r+vh
      if vs.r<r1 && ve.r<r1
        puts " "+((vs+v0).to_a+(ve+v0).to_a).join(" ")        if opt==1
        puts " "+((mx*vs).to_a+(mx*ve).to_a).join(" ")        if opt>=2
        puts " "+((mk*mx*vs).to_a+(mk*mx*ve).to_a).join(" ")  if opt==-5
      elsif vs.r<r1
        puts " "+((vs+v0).to_a+(vp+v0).to_a).join(" ")        if opt==1
        puts " "+((mx*vs).to_a+(mx*vp).to_a).join(" ")        if opt>=2
        puts " "+((mk*mx*vs).to_a+(mk*mx*vp).to_a).join(" ")  if opt==-5
      elsif (ve-vs).dot(vq-vs)>0 && (ve-vs).dot(vp-vs)>0
        puts " "+((vq+v0).to_a+(vp+v0).to_a).join(" ")        if opt==1
        puts " "+((mx*vq).to_a+(mx*vp).to_a).join(" ")        if opt>=2
        puts " "+((mk*mx*vq).to_a+(mk*mx*vp).to_a).join(" ")  if opt==-5
      end
    end
  elsif jw.match(/^ci (.*)/) #円の処理
    ci=$1.split(" ").map{|f| f.to_f}
    cc=Vector.elements(ci[0,2])
    cc=cc-v0                #円弧中心
    r2=ci[2]                #半径
    d=cc.r                  #円と円の距離
    ch=(ci[5] ? ci[5] :1.0)  #扁平率
    cj=(ci[6] ? ci[6] :0.0)  #軸角
    if d>r1+r2 #円が離れている場合
      next
    elsif d<r1-r2 or (cc.r==0 && r1==r2)    #円の中に円がある又は円が同一
      puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} "+ci[3..6].join(" ") if opt==1
      puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} "+ci[3..6].join(" ") if opt>=2
      if opt==-5 && ci[3] #円弧か楕円
        puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} "+
          ci[3..5].join(" ")+" #{(cj+rd)%360.0}"
      elsif opt==-5
        puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n}"
      end
    else #交点が存在する場合
      if ch<1.0 #楕円の場合はそのまま出力
        puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} "+ci[3..6].join(" ") if opt==1
        puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} "+ci[3..6].join(" ") if opt>=2
        puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} "+
          ci[3..5].join(" ")+" #{(cj+rd)%360.0}"  if opt==-5
      else
        rad=acos((d**2+r1**2-r2**2)/(2*d*r1)) #余弦定理
        ma=Matrix[[cos(rad),sin(rad)],[-sin(rad),cos(rad)]]
        mb=Matrix[[cos(rad),-sin(rad)],[sin(rad),cos(rad)]]
        vp=ma*cc*(r1/d) #交点1
        vq=mb*cc*(r1/d) #交点2
        vc=Vector[r2,0]
        dp=atan2((vp-cc)[1],(vp-cc)[0])*180/PI
        dq=atan2((vq-cc)[1],(vq-cc)[0])*180/PI
        dp=dp+360.0 if dp<0
        dq=dq+360.0 if dq<0
        dp,dq=[dp,dq].sort
        if ci.size==3 #円の場合
          dp,dq=dq,dp if (vc+cc).r<r1 #0°の点が円の外
          puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} #{dp} #{dq} 1.0 0" if opt==1
          puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} #{dp} #{dq} 1.0 0" if opt>=2
          puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} #{dp} #{dq} "+
            "1.0 #{rd}" if opt==-5
        else #円弧の場合
          ds,de=ci[3]+cj,ci[4]+cj #始角と終角
          de=(de-ds<0 ? de-ds+360.0 : de-ds)
          dp,dq=[dp,dq].map{|e| e-ds<0 ? e-ds+360.0 : e-ds}.sort
          ms=Matrix[[cos(ds*PI/180),-sin(ds*PI/180)],[sin(ds*PI/180),cos(ds*PI/180)]]
          if dq<de #交点が2つ
            if (ms*vc+cc).r<r1 #始点が円内
              dp,dq,de=[dp,dq,de].map{|e| (e+ds)%360}
              puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} #{ds} #{dp} 1.0 0" if opt==1
              puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} #{dq} #{de} 1.0 0" if opt==1
              puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} #{ds} #{dp} 1.0 0" if opt>=2
              puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} #{dq} #{de} 1.0 0" if opt>=2
              puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} #{ds} #{dp} "+
                "1.0 #{(cj+rd)%360.0}" if opt==-5
              puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} #{dq} #{de} "+
                "1.0 #{(cj+rd)%360.0}" if opt==-5
            else
              dp,dq,de=[dp,dq,de].map{|e| (e+ds)%360}
              puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} #{dp} #{dq} 1.0 0" if opt==1
              puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} #{dp} #{dq} 1.0 0" if opt>=2
              puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} #{dp} #{dq} "+
                "1.0 #{(cj+rd)%360.0}" if opt==-5
            end
          elsif dp<de #交点が1つ
            dp,dq,de=[dp,dq,de].map{|e| (e+ds)%360}
            if (ms*vc+cc).r<r1 #始点が円内
              puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} #{ds} #{dp} 1.0 0" if opt==1
              puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} #{ds} #{dp} 1.0 0" if opt>=2
              puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} #{ds} #{dp} "+
                "1.0 #{(cj+rd)%360.0}" if opt==-5
            else
              puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} #{dp} #{de} 1.0 0" if opt==1
              puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} #{dp} #{de} 1.0 0" if opt>=2
              puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} #{dp} #{de} "+
                "1.0 #{(cj+rd)%360.0}" if opt==-5
            end
          else de<dp #円弧が円内
            dp,dq,de=[dp,dq,de].map{|e| (e+ds)%360}
            if (ms*vc+cc).r<r1 #始点が円内
              puts "ci "+(cc+v0).to_a.join(" ")+" #{r2} #{ds} #{de} 1.0 0" if opt==1
              puts "ci "+(mx*cc).to_a.join(" ")+" #{r2*n} #{ds} #{de} 1.0 0" if opt>=2
              puts "ci "+(mk*mx*cc).to_a.join(" ")+" #{r2*n} #{ds} #{de} "+
                "1.0 #{(cj+rd)%360.0}" if opt==-5
            end
          end
        end
      end
    end
  else
    puts jw
  end}
__END__

:END

anonymous No title
Ruby
<?php  
$script_name=$_SERVER["SCRIPT_NAME"];
$dataFile ='kadai2-5.txt';  

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  if (isset($_POST['delete'])){ //削除ボタンが押されたら
    $delete = $_POST['delete'];
    $delCon = file("kadai2-5.txt");
      for ($j = 0; $j < count($delCon) ; $j++){ 
        $delData = explode("<>", $delCon[$j]);

        if ($delData[0] == $delete) { 
          array_splice($delCon, $j, 1);
          file_put_contents($dataFile,  $delCon);
          header("location:$script_name");
        }
      }
  }
    //入力フォームのデータを受け取る
    $blank = 11;
    if(isset($_POST["user"])&&isset($_POST["message"])){
      if($_POST["user"] == ""||$_POST["message"] == ""){
        $blank = 10;
        }else{
          $count = (sizeof(file($dataFile)) + 1);
          $message = ($_POST['message']);  
          $user = ($_POST['user']);  
          $postedAt = date('Y-m-d H:i:s');  
          
          // まとめた変数
          $newData = $count."<>".$message."<>".$user."<>".$postedAt. "\n"; 
          
          $fp = fopen($dataFile,'a');  
          fwrite($fp, $newData);  
          fclose($fp);  
          header("location:$script_name");
        }  
    }
} 
 ?>  

<!DOCTYPE html>
<html lang="ja">
  <head>
      <meta charset="UTF-8" />
      <title>簡易掲示板</title>
  </head>
  <body>
      <h1>簡易掲示板</h1>

      <!-- 投稿用フォーム -->
      <form action="" method="post">
      <table>
      <tr><td>名前: </td>
      <td><input type="text" name="user"></td></tr>
      <tr><td>コメント: </td>
      <td><textarea name="message" cols="30" rows="5"></textarea></td></tr>
      <tr><td><input type="submit" value="投稿"></td></tr>
      </table>
      </form>

      <!--削除用フォーム-->
      <form action="" method="post"> 
      <p>削除対象番号<input type="text" name="delete"></p> 
      <input type="submit" name="deleteNo" value="削除"> 
     </form>
     
      <p>______________________________</p>
      <!-- 編集用フォーム -->
      <p>編集したい番号を半角数字で入力してください。</p>
       <form action="<?php echo($_SERVER['PHP_SELF'])?>" method="post">
      <input type="text" name="edit_num" value="<?= isset('$edit_num']) ? $_POST['edit_num'] : null ?>">
      <input type="submit" name="edit_btn" value="編集する">
      <input type="hidden" name="edit" value="henshu">
      </form>

      <?php
      if(isset($_POST["edit_btn"])){ //編集ボタンが押されたら
        if($_POST["edit_num"]){
          $edit_num = $_POST["edit_num"];
          foreach ($contents as $content){
            $parts = explode("<>",$content);
            if($parts[0] == $edit_num){
      ?>

      <form action="<?php echo($_SERVER['PHP_SELF'])?>" method="post">
      <input type="hidden" name="id" value="<?= $parts[0] ?>">
      <table>
      <tr><td>名前:</td>
      <td><input type="text"name="name" value="<?= $parts[1] ?>"></td></tr>
      <tr><td>コメント:</td>
      <td><textarea type="text" name="comment" cols="30" rows="5"><?= $parts[2] ?></textarea></td></tr>
      <tr><td><input type="submit" name="submit" value="送信"></td></tr>
      </table>
      </form>
      <?php
            }
          }
        }else{
          echo"編集する番号を入力してください。";
        }
      }
      ?>
      <?php
      // ファイルの内容を配列に格納 
      $file_name = file("kadai_2_5.txt");
      $contents = file("kadai_2_5.txt");
      foreach ($contents as $content) {
        $parts = explode("<>",$content);
        foreach ($parts as $part) {
          echo "<table><tr>$part</tr><table>";
        }
      }
      ?>

  </body>
</html>
中学生プログラマーRails No title
Ruby
#!/usr/bin/env ruby

# This file loads Spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
  require 'rubygems'
  require 'bundler'

  lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
  spring = lockfile.specs.detect { |spec| spec.name == 'spring' }
  if spring
    Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
    gem 'spring', spring.version
    require 'spring/binstub'
  end
end
anonymous No title
Ruby
class Post < ApplicationRecord
	mount_uploader :image, ImageUploader
	validates :body, presence: true
	validates :title, presence: true
	belongs_to :user
	has_many :likes,dependent: :destroy
	has_many :liked_users, through: :likes, source: :user,dependent: :destroy
	is_impressionable counter_cache: true
	has_many :comments,dependent: :destroy
	has_many :star, dependent: :destroy

	 #ratyrate_rateable "title"
# def self.search(search)
# 	 if search
#        where(['username LIKE ?', "%#{search}%"]) #検索とuseanameの部分一致を表示。
#      else
#        all #全て表示させる
#     end
#  end

end
anonymous No title
Ruby
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_11_06_084855) do

  create_table "average_caches", force: :cascade do |t|
    t.integer "rater_id"
    t.string "rateable_type"
    t.integer "rateable_id"
    t.float "avg", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["rateable_type", "rateable_id"], name: "index_average_caches_on_rateable_type_and_rateable_id"
    t.index ["rater_id"], name: "index_average_caches_on_rater_id"
  end

  create_table "comments", force: :cascade do |t|
    t.string "content"
    t.integer "user_id"
    t.integer "post_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer "star"
    t.index ["post_id"], name: "index_comments_on_post_id"
    t.index ["user_id"], name: "index_comments_on_user_id"
  end

  create_table "impressions", force: :cascade do |t|
    t.string "impressionable_type"
    t.integer "impressionable_id"
    t.integer "user_id"
    t.string "controller_name"
    t.string "action_name"
    t.string "view_name"
    t.string "request_hash"
    t.string "ip_address"
    t.string "session_hash"
    t.text "message"
    t.text "referrer"
    t.text "params"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["controller_name", "action_name", "ip_address"], name: "controlleraction_ip_index"
    t.index ["controller_name", "action_name", "request_hash"], name: "controlleraction_request_index"
    t.index ["controller_name", "action_name", "session_hash"], name: "controlleraction_session_index"
    t.index ["impressionable_type", "impressionable_id", "ip_address"], name: "poly_ip_index"
    t.index ["impressionable_type", "impressionable_id", "params"], name: "poly_params_request_index"
    t.index ["impressionable_type", "impressionable_id", "request_hash"], name: "poly_request_index"
    t.index ["impressionable_type", "impressionable_id", "session_hash"], name: "poly_session_index"
    t.index ["impressionable_type", "message", "impressionable_id"], name: "impressionable_type_message_index"
    t.index ["user_id"], name: "index_impressions_on_user_id"
  end

  create_table "likes", force: :cascade do |t|
    t.integer "post_id"
    t.integer "user_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["post_id"], name: "index_likes_on_post_id"
    t.index ["user_id"], name: "index_likes_on_user_id"
  end

  create_table "mypages", force: :cascade do |t|
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "image"
  end

  create_table "overall_averages", force: :cascade do |t|
    t.string "rateable_type"
    t.integer "rateable_id"
    t.float "overall_avg", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["rateable_type", "rateable_id"], name: "index_overall_averages_on_rateable_type_and_rateable_id"
  end

  create_table "posts", force: :cascade do |t|
    t.string "title"
    t.text "body"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer "user_id"
    t.string "image"
    t.integer "impressions_count"
  end

  create_table "rating_caches", force: :cascade do |t|
    t.string "cacheable_type"
    t.integer "cacheable_id"
    t.float "avg", null: false
    t.integer "qty", null: false
    t.string "dimension"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["cacheable_type", "cacheable_id"], name: "index_rating_caches_on_cacheable_type_and_cacheable_id"
  end

  create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.string "confirmation_token"
    t.datetime "confirmed_at"
    t.datetime "confirmation_sent_at"
    t.string "unconfirmed_email"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.boolean "admin", default: false
    t.string "name"
    t.boolean "accepted", default: false, null: false
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

end
anonymous No title
Ruby
class CommentsController < ApplicationController
	def create
		@comment = Comment.new(comment_params)
		@comment.user_id = current_user.id
		if @comment.save!
			redirect_back(fallback_location: root_path)
		else
			redirect_back(fallback_location: root_path)

		end
	end

	private
	def comment_params
		params.require(:comment).permit(:content)
	end
end
anonymous No title
Ruby
# coding: utf-8

class Test
  def initialize(value)
  end

  def transpose(amount)
    "" 
  end
end
anonymous No title
Ruby
💩
anonymous No title
Ruby
def aaa
  "unko"
end
anonymous No title
Ruby
nil
Don't you submit code?
Submit
12