Skip to content

Instantly share code, notes, and snippets.

@ir-norn
ir-norn / task.rb
Last active September 25, 2015 03:25
task
class Task
def initialize
@func =->{yield self}
end
def update
@func.call
end
end
@ir-norn
ir-norn / tes.rb
Last active September 25, 2015 04:19
instance_evalの使い道
#coding:utf-8
# 2015 09 24 Req
require"dxruby"
class O
attr_accessor :x,:y,:d,:f,:task
def initialize h = {}
@x = h[:x]
@y = h[:y]
@d = h[:d]
require "observer"
require "dxruby"
class Observer
include Observable
end
class O
attr_accessor :x , :y , :d , :func
def initialize x , y , d , func
# coding : utf-8
require "dxruby"
def move x , y , s , a
x += (s * Math::cos(a * Math::PI/180 ))
y += (s * Math::sin(a * Math::PI/180 ))
[x , y , s , a]
end
def DegToRad x
module Rationalize
refine Fixnum do
def /(other)
quo(other)
end
end
end
p 1 / 2
#require "Fiber"
class Enum_Generator
def initialize re , method
@f = Fiber.new do
re.__send__(method) do | n |
Fiber.yield n
end
end
end
nums = [1,2,3,4,5,1,2,2,3]
p nums.itself { |s| s.inject(:+) / s.size.to_f } # => 2.5555555555555554
p nums.inject(:+) / nums.size.to_f # => 2.5555555555555554
p nums.group_by(&:itself) # => {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]}
@ir-norn
ir-norn / Xnview_webp_jpg_conert.rb
Created October 1, 2015 18:25
chrome data saver
#
# webp jpg
# フォルダが存在すればtrue
if system"copy *.* tmp\\*.*"
system"nconvert -D -out jpeg *.jpg"
Dir["*.*"].each do|m|
next if File.extname(m) == ".rb" # rb script だけ除外
# _1 がつくのでそれをrename
b = File.basename(m, '.*')
@ir-norn
ir-norn / div.html
Last active October 12, 2015 01:43
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title></title>
</head>
<body>
<style><!--
div { background: #bbb;
height : 50px;
width : 50px;
<style><!--
div.body { display:none }
div.entry_border { opacity:0.3 }
article.page { display:none }
--></style>
<script><!--
$(document).ready(function() {
/* $('body').fadeIn(1400); */