Skip to content

Instantly share code, notes, and snippets.

@parrot-studio
parrot-studio / ccpts_react.js.jsx.coffee
Last active August 29, 2015 14:15
react.jsをお試し中
searchArcanas = (query, path, component, callback) ->
component.setState(showError: false)
$("#loading-modal").modal('show')
query ?= {}
query.ver = $("#data-ver").val()
url = $("#app-path").val() + path
callbacks =
done: (as) ->
callback(as, component)
$("#loading-modal").modal('hide')
class Fibonacci
class << self
include Enumerable
def each
(1..Float::INFINITY).lazy.each do |i|
yield fib(i)
end
end
https://paiza.jp/poh/enkoi
Ruby / CoffeeScript
# 再帰的探査
def search(list, i, need, nco, maxind, mincost, limit_mem)
c = list[i]
nmem = need - c[0]
cost = nco + c[1]
return mincost if cost > mincost # すでにわかっている答えより大きいので無駄
return cost if nmem <= 0 # メンバーが埋まった
return mincost if i >= maxind # 終端までいったが、メンバーが埋まらない
# 自身の効率*残り人数+現在のcostがmincostを超える
height, width = gets.split(' ').map(&:to_i)
# bitとして扱う
lines = []
(1..height).each do |h|
lines << gets.chomp.to_i(2)
end
# 対象を解析
targets = {}
# coding: utf-8
def read_data(count)
c = count.to_i
return if c < 0
ret = []
count.times do
s = gets
next unless s
ret << s.to_i
end
@parrot-studio
parrot-studio / mini.rb
Last active December 28, 2015 02:18
miniが待てないんだよщ(゚Д゚щ)
# encoding: utf-8
require 'mail'
MAIL_ENCODING = 'ISO-2022-JP'
MYADDR = "hogehoge"
def send_message
mes = "mini来た!!"
m = Mail.new
@parrot-studio
parrot-studio / geolocation.rb
Created September 13, 2013 00:49
座標系の計算モジュール 2点間の距離算出と、ある地点からNメートルの範囲にある緯度/経度範囲の算出 (ほとんど他の方のBlogのパクリであまりよろしくない) 実際は方形で大雑把に絞り込んだ後、具体的な各地点間の距離を算出し、 「半径Nメートル以内にあるポイント」を絞り込んでいる
# coding: utf-8
module Geolocation
def distance_to(lat, lon, mode = nil)
return unless (lat && lon)
return unless (self.respond_to?(:latitude) && self.respond_to?(:longitude))
earth_distance(self.latitude, self.longitude, lat, lon, mode)
end
def distance_between(point, mode = nil)
@parrot-studio
parrot-studio / BF.scala
Last active December 20, 2015 16:29
BrainF**k interpreter by Scala (confirmed by 2.10.2)
import scala.annotation.tailrec
object BF {
class Parser(val str: String) {
val cmap = Map(
">" -> 'pinc,
"<" -> 'pdec,
"+" -> 'inc,
"-" -> 'dec,
@parrot-studio
parrot-studio / fizzbuzz.rb
Created August 8, 2012 04:38
FizzBuzzを書いたことがないとまずいらしいので・・・
# coding: utf-8
(1..100).each do |n|
puts case
when n % 15 == 0
'FizzBuzz'
when n % 3 == 0
'Fizz'
when n % 5 == 0
'Buzz'
else