Skip to content

Instantly share code, notes, and snippets.

class Tetoroid
def self.recognize(inputs)
return "-" if inputs.uniq.size != 4
coordinates = inputs.map {|n| n.divmod(10) }
# g means gravity
gx, gy = coordinates.transpose.map {|array| array.inject(&:+).to_f / array.size }
distances = coordinates.map {|x, y| (x - gx)**2 + (y - gy)**2 }.sort # dare not sqrt
@okitan
okitan / gist:4564339
Created January 18, 2013 12:44
なんとなく
module Dispatchable
def self.included(base)
base.module_eval {
def self.method_added(name)
suffix = self.name.split("::").last.downcase
return if name.to_s.end_with?(suffix)
module_eval %{
alias #{name}_#{suffix} #{name}
undef #{name}
@okitan
okitan / shell.rb
Last active December 16, 2015 10:58
朝の頭の体操
# -*- coding: utf-8 -*-
class Shell < BasicObject
def initialize(name, *args, &block)
_push(name, *args)
end
attr_accessor :_result
attr_writer :_queue
def to_s
@okitan
okitan / selenium_webdriver_for_chromedriver2.rb
Last active December 22, 2015 21:39
DEPRECATED: This monkey patch is no longer needed. Use slenium-webdriver >= 2.37.0 ! monkey patch for selenium-webdriver to work with chromedriver2
require "selenium/webdriver"
require "selenium/webdriver/chrome"
module Selenium
module WebDriver
module Chrome
class Bridge
def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.chrome }
args = opts.delete(:args) || opts.delete(:switches)
@okitan
okitan / Logs
Created March 14, 2018 06:03
webdriver.io --watch mode issues
$ npx wdio --watch --spec test.js
[15:00:44] COMMAND POST "/session"
[15:00:44] DATA {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"maxInstances":5,"browserName":"chrome","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requ
estOrigins":{"url":"http://webdriver.io","version":"4.12.0","name":"webdriverio"}}}
[15:00:46] INFO SET SESSION ID b0083dcf4ed26c3e9de5873e9b7d2393
[15:00:46] RESULT {"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.36.540469 (1881fd7f8641508feb5166b7
cae561d87723cfa8)","userDataDir":"/var/folders/c7/7pqwpv895y31b3n67b4l2tj5hwytzk/T/.org.chromium.Chromium.E1IHhg"},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locati
onContextEnabled":true,"mobileEmulationEnabled":false,"nativ