Skip to content

Instantly share code, notes, and snippets.

@track8
track8 / kanagawa.rb
Created January 17, 2015 05:38
神奈川Ruby会議のペアプロで作ったやつ(http://nabetani.sakura.ne.jp/kanagawa.rb/evalex/)
def kanagawa(str)
f = str.scan(/[0-9]+|[^0-9]/)
['|', '&', '+', '*'].each do |op|
while(i = f.index(op)) do
f[(i - 1)..(i + 1)] = eval(f[(i - 1)..(i + 1)].join(''))
end
end
f[0]
end
@track8
track8 / afx.rb
Last active August 29, 2015 14:14
require 'open-uri'
require 'open_uri_redirections'
require 'soundcloud'
OUTDIR = 'user48736353001'
Dir.mkdir(OUTDIR) unless Dir.exists? OUTDIR
def save(title, download_url)
puts title
file_name = "#{OUTDIR}/#{title}.mp3"
@track8
track8 / simple.rb
Created March 4, 2015 19:41
toRuby 99まで
class Number < Struct.new(:value)
def to_s
value.to_s
end
def inspect
"<<#{self}>>"
end
def reducible?
@track8
track8 / hello_yarv.rb
Created March 18, 2015 14:12
Hello YARV
code = <<END
puts "Hello World!"
END
puts RubyVM::InstructionSequence.compile(code).disasm
def formula_ptn(ptn)
ope = ptn.to_s(3).rjust(8, '0').gsub('0', 'n').gsub('1', '+').gsub('2', '-')
(1..9).map(&:to_s).each_with_index.inject('') do |result, (num, index)|
result += num
if ope[index] && ope[index] != 'n'
result += ope[index]
end
result
end
end
@track8
track8 / gist:3446989
Created August 24, 2012 07:09
C# hash
using System;
using System.Collections.Generic;
using System.Linq;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
#http://icpc2010.honiden.nii.ac.jp/domestic-contest/problems#section_A
class Kaku
def initialize(paterns)
@paterns = paterns
end
def ans
return "1 1" if @paterns.empty?
coordinates = @paterns.inject([[0, 0]]) do |c, p|
i = c[p[0]]
@track8
track8 / config.ru
Created February 6, 2013 14:49
>> rackup
# config.ru
require 'rack'
require 'gdk_pixbuf2'
class AvatarClone
def call(env)
request = Rack::Request.new(env)
case request.request_method
when 'GET'
begin
@track8
track8 / countdown_timer.rb
Last active December 14, 2015 01:29
タイマ習作
# -*- coding: utf-8 -*-
require 'gtk2'
class CountdownTimer
def initialize(minutes, &block)
@default_block = block
reset(minutes, &block)
end
def expected_time