パルカワ2

最近はFlutterをやっています

Myoを使って、グッとしてファボる。

ドラゴンボールとか、気で相手吹き飛ばしたりしてる。かっこいい。やりたい。
でも、現実的に人間吹き飛ばすとかムリ 俺はそんな野蛮な人間ではない。
なので、グッてするだけでツイートファボることにした。


グッとしてファボ from hisaichi5518 on Vimeo.

Myoでやってる。ドキュメント見ながら、ピッて書いたら動いた。

Yorufukurou = {}
function Yorufukurou:new (o)
    o = o or {}
    setmetatable(o, self)
    self.__index = self
    return o
end

function Yorufukurou:fav()
    myo.keyboard("f", "press")
end

function onPoseEdge(pose, edge)
    if edge == "on" and pose == "fist" then
        fukurou:fav()
        myo.lock("timed")
    end
end

function onPeriodic()
end

function onActiveChange(isActive)
end

scriptId = 'com.hisaichi5518.scripts.Yorufukurou'
scriptDetailsUrl = 'http://hisaichi5518.hatenablog.jp'
scriptTitle = 'Yorufukurou Fav'

fukurou = Yorufukurou:new()

function onForegroundWindowChange(app, title)
    return true
end

function activeAppName()
    return "YoruFukurou"
end

簡単便利

deviseで登録時に本人確認メールを送信するが、本人確認してなくてもログイン出来るようにする。

使ってるバージョンは、3.4.1。

# Checks if the confirmation for the user is within the limit time.
# We do this by calculating if the difference between today and the
# confirmation sent date does not exceed the confirm in time configured.
# Confirm_within is a model configuration, must always be an integer value.
#
# Example:
#
#   # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today
#   confirmation_period_valid?   # returns true
#
#   # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago
#   confirmation_period_valid?   # returns true
#
#   # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago
#   confirmation_period_valid?   # returns false
#
#   # allow_unconfirmed_access_for = 0.days
#   confirmation_period_valid?   # will always return false
#
#   # allow_unconfirmed_access_for = nil
#   confirmation_period_valid?   # will always return true
#
def confirmation_period_valid?
  self.class.allow_unconfirmed_access_for.nil? || (confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago)
end

https://github.com/plataformatec/devise/blob/master/lib/devise/models/confirmable.rb#L166
このあたり見たら書いてた。

# config/initializers/devise.rb
Devise.setup do |config|
  config.allow_unconfirmed_access_for = nil
end

とすると出来るようになる。
allow_unconfirmed_access_forは、普通1.dayだとかが入るらしいけど、nilだと無条件にオッケーになる。

それ以外にもこう書けばよいみたいなのも見つけた。
https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users#allowing-unconfirmed-access

protected
def confirmation_required?
  false
end

ただ、コードを見ていると登録時にはメールが送られなさそうだな〜と思ったのでとりあえずnilにする方を採用した。(試していないのはなるべく早く実装したかった)