Created
January 9, 2013 05:08
-
-
Save morygonzalez/4490769 to your computer and use it in GitHub Desktop.
earthquake.gem で必ず140文字投稿する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# always tweet with 140 characters | |
# port of https://gist.github.com/453709 | |
# | |
Earthquake.init do | |
command :t140 do |m| | |
max = 140 | |
body = m[1] | |
len = body.length | |
mod = max % len | |
ext = (0..len).to_a.sort_by { rand }.take(mod) | |
str = body.split(//).each_with_index.map {|c, i| | |
c * (max / len + (ext.include?(i) ? 1 : 0)) | |
}.join('') | |
input str | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment