Skip to content

Commit 5dd5e47

Browse files
committedMar 19, 2018
Prefer && and || over "and" and "or".
1 parent e65d1cc commit 5dd5e47

11 files changed

+34
-34
lines changed
 

‎.irbrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
env = (ENV["IRB_PROMPT"] || ENV["APP_ENV"] || ENV["RACK_ENV"] || "unknown").upcase
2-
if env == "PRODUCTION" or env == "DEPLOYMENT"
2+
if env == "PRODUCTION" || env == "DEPLOYMENT"
33
color = "31"
44
else
55
color = "33"

‎app.rb

+13-13
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@
7373
get "/twitter" do
7474
return "Insufficient parameters" if params[:q].empty?
7575

76-
if params[:q]["twitter.com/i/"] or params[:q]["twitter.com/who_to_follow/"]
76+
if params[:q]["twitter.com/i/"] || params[:q]["twitter.com/who_to_follow/"]
7777
return "Unsupported url. Sorry."
7878
elsif params[:q]["twitter.com/hashtag/"]
7979
return "This app does not support hashtags. Sorry."
80-
elsif /twitter\.com\/(?:#!\/|@)?(?<user>[^\/?#]+)/ =~ params[:q] or /@(?<user>[^\/?#]+)/ =~ params[:q]
80+
elsif /twitter\.com\/(?:#!\/|@)?(?<user>[^\/?#]+)/ =~ params[:q] || /@(?<user>[^\/?#]+)/ =~ params[:q]
8181
# https://twitter.com/#!/infected
8282
# https://twitter.com/infected
8383
# @username
@@ -243,7 +243,7 @@
243243
else
244244
# it's probably a username
245245
user = params[:q]
246-
user = "+#{user}" if user[0] != "+" and !user.numeric?
246+
user = "+#{user}" if user[0] != "+" && !user.numeric?
247247
end
248248

249249
response = Google.get("/plus/v1/people/#{CGI.escape(user)}")
@@ -291,7 +291,7 @@
291291
response = Vimeo.get("/videos/#{video_id}")
292292
raise(VimeoError, response) if !response.success?
293293
user_id = response.json["user"]["uri"][/\d+/]
294-
elsif /vimeo\.com\/(?:channels\/)?(?<user>[^\/?&#]+)/ =~ params[:q] or user = params[:q]
294+
elsif /vimeo\.com\/(?:channels\/)?(?<user>[^\/?&#]+)/ =~ params[:q] || user = params[:q]
295295
# it's probably a channel name
296296
response = Vimeo.get("/users", query: { query: user })
297297
raise(VimeoError, response) if !response.success?
@@ -420,7 +420,7 @@
420420
# This is not the best quality of the picture, but it will have to do
421421
url = CGI.unescapeHTML($&)
422422
end
423-
if /<title[^>]*>(?<title>[^<]+)<\/title>/ =~ response.body and /data-utime="(?<utime>\d+)"/ =~ response.body
423+
if /<title[^>]*>(?<title>[^<]+)<\/title>/ =~ response.body && /data-utime="(?<utime>\d+)"/ =~ response.body
424424
title = title.force_encoding("UTF-8").gsub(" | Facebook", "")
425425
created_time = Time.at(utime.to_i)
426426
fn = "#{created_time.to_date} - #{title}.#{url.url_ext}".to_filename
@@ -467,7 +467,7 @@
467467
# Filter posts if with=uid is supplied (property only exists on posts)
468468
if params[:with]
469469
ids = params[:with].split(",")
470-
@data.select! { |post| post["with_tags"] and post["with_tags"]["data"].any? { |tag| ids.include?(tag["id"]) } }
470+
@data.select! { |post| post["with_tags"] && post["with_tags"]["data"].any? { |tag| ids.include?(tag["id"]) } }
471471
elsif params.has_key?(:with)
472472
# If with is specified but is nil, then we just want to get posts that include someone else
473473
@data.select! { |post| post["with_tags"] }
@@ -477,7 +477,7 @@
477477
@data.each do |post|
478478
if post["properties"]
479479
post["properties"].each do |prop|
480-
if prop["name"] == "Length" and /^(?<m>\d+):(?<s>\d+)$/ =~ prop["text"]
480+
if prop["name"] == "Length" && /^(?<m>\d+):(?<s>\d+)$/ =~ prop["text"]
481481
post["length"] = 60*m.to_i + s.to_i
482482
end
483483
end
@@ -703,7 +703,7 @@
703703
uri = Addressable::URI.parse(response.json["location"])
704704
return "URL does not resolve to a user." if !uri.path.start_with?("/users/")
705705
id = uri.path[/\d+/]
706-
elsif response.code == 404 and username.numeric?
706+
elsif response.code == 404 && username.numeric?
707707
response = Soundcloud.get("/users/#{username}")
708708
return "Can't find a user with that id. Sorry." if response.code == 404
709709
raise(SoundcloudError, response) if !response.success?
@@ -822,7 +822,7 @@
822822
if /clips\.twitch\.tv\/(?:embed\?clip=)?(?<clip_slug>[^?&#]+)/ =~ params[:url]
823823
# https://clips.twitch.tv/majinphil/UnusualClamRaccAttack
824824
# https://clips.twitch.tv/embed?clip=majinphil/UnusualClamRaccAttack&autoplay=false
825-
elsif /twitch\.tv\/videos\/(?<vod_id>\d+)/ =~ params[:url] or /twitch\.tv\/(?:[^\/]+)\/v\/(?<vod_id>\d+)/ =~ params[:url] or /(^|v)(?<vod_id>\d+)/ =~ params[:url]
825+
elsif /twitch\.tv\/videos\/(?<vod_id>\d+)/ =~ params[:url] || /twitch\.tv\/(?:[^\/]+)\/v\/(?<vod_id>\d+)/ =~ params[:url] || /(^|v)(?<vod_id>\d+)/ =~ params[:url]
826826
# https://www.twitch.tv/videos/25133028
827827
# https://www.twitch.tv/gamesdonequick/v/34377308?t=53m40s
828828
# https://player.twitch.tv/?video=v103620362
@@ -870,7 +870,7 @@
870870
if /clips\.twitch\.tv\/(?:embed\?clip=)?(?<clip_slug>[^?&#]+)/ =~ params[:url]
871871
# https://clips.twitch.tv/majinphil/UnusualClamRaccAttack
872872
# https://clips.twitch.tv/embed?clip=majinphil/UnusualClamRaccAttack&autoplay=false
873-
elsif /twitch\.tv\/videos\/(?<vod_id>\d+)/ =~ params[:url] or /twitch\.tv\/(?:[^\/]+)\/v\/(?<vod_id>\d+)/ =~ params[:url] or /(^|v)(?<vod_id>\d+)/ =~ params[:url]
873+
elsif /twitch\.tv\/videos\/(?<vod_id>\d+)/ =~ params[:url] || /twitch\.tv\/(?:[^\/]+)\/v\/(?<vod_id>\d+)/ =~ params[:url] || /(^|v)(?<vod_id>\d+)/ =~ params[:url]
874874
# https://www.twitch.tv/videos/25133028
875875
# https://www.twitch.tv/gamesdonequick/v/34377308?t=53m40s
876876
# https://player.twitch.tv/?video=v103620362
@@ -1029,7 +1029,7 @@
10291029
get "/dailymotion" do
10301030
return "Insufficient parameters" if params[:q].empty?
10311031

1032-
if /dailymotion\.com\/video\/(?<video_id>[a-zA-Z0-9]+)/ =~ params[:q] or /dai\.ly\/(?<video_id>[a-zA-Z0-9]+)/ =~ params[:q]
1032+
if /dailymotion\.com\/video\/(?<video_id>[a-zA-Z0-9]+)/ =~ params[:q] || /dai\.ly\/(?<video_id>[a-zA-Z0-9]+)/ =~ params[:q]
10331033
# http://www.dailymotion.com/video/x3r4xy2_recut-9-cultural-interchange_fun
10341034
# http://www.dailymotion.com/video/k1ZotianZxwzm6fmny2
10351035
# http://dai.ly/x4bzwj4?start=60
@@ -1089,7 +1089,7 @@
10891089
# https://www.reddit.com/r/aww
10901090
redirect "/imgur/r/#{subreddit}#{"?#{params[:type]}" if !params[:type].empty?}"
10911091
return
1092-
elsif /(?<username>[a-zA-Z0-9]+)\.imgur\.com/ =~ params[:q] and username != "i"
1092+
elsif /(?<username>[a-zA-Z0-9]+)\.imgur\.com/ =~ params[:q] && username != "i"
10931093
# https://thebookofgray.imgur.com/
10941094
elsif /imgur\.com\/(gallery\/)?(?<image_id>[a-zA-Z0-9]+)/ =~ params[:q]
10951095
# https://imgur.com/NdyrgaE
@@ -1137,7 +1137,7 @@
11371137
# can't use user_id in this request unfortunately
11381138
response = Imgur.get("/account/#{@username}/submissions")
11391139
end
1140-
raise(ImgurError, response) if !response.success? or response.body.empty?
1140+
raise(ImgurError, response) if !response.success? || response.body.empty?
11411141
@data = response.json["data"]
11421142

11431143
if params[:animated]

‎config/initializers/05-airbrake.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
Airbrake.add_filter do |notice|
1414
# Bots gonna bot
15-
notice.ignore! if notice[:errors].any? { |e| e[:type] == "Sinatra::NotFound" } and (/\/wp-(?:admin|includes|content|login)/ =~ notice[:context][:url] or /\/facebook\/\d+\/?$/ =~ notice[:context][:url])
15+
notice.ignore! if notice[:errors].any? { |e| e[:type] == "Sinatra::NotFound" } && (/\/wp-(?:admin|includes|content|login)/ =~ notice[:context][:url] || /\/facebook\/\d+\/?$/ =~ notice[:context][:url])
1616
end
1717
end

‎config/initializers/05-integer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def to_filesize(digits=2)
1616
units = %w[B kB MB GB TB PB EB ZB YB]
1717
n = self
1818
i = 0
19-
while n > 1000 and i < units.length do
19+
while n > 1000 && i < units.length do
2020
n = n / 1000.0
2121
i += 1
2222
end

‎config/initializers/05-string.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,25 @@ def linkify_and_embed(request=nil, embed_only="")
194194
result.gsub!(URL_REGEXP) do |url|
195195
dest = url.resolve_url
196196
html = dest.embed_html(request)
197-
embeds.push(html) if html and !embeds.include?(html)
197+
embeds.push(html) if html && !embeds.include?(html)
198198
"<a href='#{dest.esc}' title='#{url.esc}' rel='noreferrer'>#{dest.esc}</a>"
199199
end
200200
embed_only.scan(URL_REGEXP) do |url|
201201
dest = url.resolve_url
202202
html = dest.embed_html(request)
203-
embeds.push(html) if html and !embeds.include?(html)
203+
embeds.push(html) if html && !embeds.include?(html)
204204
end
205205
return result + embeds.map { |html| "\n" + html }.join
206206
end
207207

208208
def embed_html(request=nil)
209209
root_url = request ? request.root_url : ""
210-
if %r{^https?://www\.facebook\.com/.*/videos/(?:vb\.\d+\/)?(?<id>\d+)} =~ self or %r{^https?://www\.facebook\.com/video/embed\?video_id=(?<id>\d+)} =~ self
210+
if %r{^https?://www\.facebook\.com/.*/videos/(?:vb\.\d+\/)?(?<id>\d+)} =~ self || %r{^https?://www\.facebook\.com/video/embed\?video_id=(?<id>\d+)} =~ self
211211
<<~EOF
212212
<iframe width="1280" height="720" src="https://www.facebook.com/video/embed?video_id=#{id}" frameborder="0" scrolling="no" allowfullscreen referrerpolicy="no-referrer"></iframe>
213213
<a href="https://www.facebook.com/video/embed?video_id=#{id}" rel="noreferrer">Open embed</a> | <a href="#{root_url}/facebook/download?url=#{id}">Download video</a> | <a href="#{root_url}/?download=#{CGI.escape("https://www.facebook.com/video/embed?video_id=#{id}")}">Download video with nice filename</a>
214214
EOF
215-
elsif %r{^https?://(?:www\.|m\.)youtube\.com/(?:.*?[?&#](v=(?<id>[^&#]+)|list=(?<list>[^&#]+)|(?:t|time_continue)=(?<t>[^&#]+)))+} =~ self or %r{^https?://(?:youtu\.be|(?:www\.)?youtube\.com/embed)/(?<id>[^?&#]+)(?:.*?[?&#](list=(?<list>[^&#]+)|(?:t|time_continue)=(?<t>[^&#]+)))*} =~ self
215+
elsif %r{^https?://(?:www\.|m\.)youtube\.com/(?:.*?[?&#](v=(?<id>[^&#]+)|list=(?<list>[^&#]+)|(?:t|time_continue)=(?<t>[^&#]+)))+} =~ self || %r{^https?://(?:youtu\.be|(?:www\.)?youtube\.com/embed)/(?<id>[^?&#]+)(?:.*?[?&#](list=(?<list>[^&#]+)|(?:t|time_continue)=(?<t>[^&#]+)))*} =~ self
216216
# https://www.youtube.com/watch?v=z5OGD5_9cA0&list=PL0QrZvg7QIgpoLdNFnEePRrU-YJfr9Be7&index=3&t=30s
217217
url = "https://www.youtube.com/embed/#{id}?rel=0"
218218
url += "&list=#{list}" if list

‎config/unicorn.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
next unless line =~ /^export /
3030
k, v = line.strip.sub(/^export /, "").split("=", 2)
3131
next if k == "PATH" # Don't update PATH
32-
v = v[1..-2] if (v[0] == '"' and v[-1] == '"') or (v[0] == "'" and v[-1] == "'")
32+
v = v[1..-2] if (v[0] == '"' && v[-1] == '"') || (v[0] == "'" && v[-1] == "'")
3333
if v == ""
3434
$stderr.puts "Unsetting ENV[#{k}]"
3535
ENV.delete k

‎lib/http.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ class HTTP
44
def self.get(url, options={headers: nil, query: nil})
55
relative_url = (url[0] == "/")
66

7-
if defined?(self::BASE_URL) and relative_url
7+
if defined?(self::BASE_URL) && relative_url
88
url = self::BASE_URL+url
99
end
1010

11-
if defined?(self::PARAMS) and relative_url
11+
if defined?(self::PARAMS) && relative_url
1212
if url["?"]
1313
url += "&"+self::PARAMS
1414
else
@@ -33,7 +33,7 @@ def self.get(url, options={headers: nil, query: nil})
3333
}
3434
Net::HTTP.start(uri.host, uri.port, opts) do |http|
3535
headers = {}
36-
headers.merge!(self::HEADERS) if defined?(self::HEADERS) and relative_url
36+
headers.merge!(self::HEADERS) if defined?(self::HEADERS) && relative_url
3737
headers.merge!(options[:headers]) if options[:headers]
3838
response = http.request_get(uri.request_uri, headers)
3939
return HTTPResponse.new(response, uri.to_s)

‎views/facebook_feed.erb

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
end
2323

2424
post["link"] = post["link"].resolve_url if post["link"]
25-
post["link"] = "https://www.facebook.com/video/embed?video_id=#{object_id}" if @edge == "videos" or (post["type"] == "video" and post["link"].start_with?("https://www.facebook.com/"))
25+
post["link"] = "https://www.facebook.com/video/embed?video_id=#{object_id}" if @edge == "videos" || (post["type"] == "video" && post["link"].start_with?("https://www.facebook.com/"))
2626
link = post["link"] || "https://www.facebook.com/#{post["id"]}"
2727
-%>
2828

2929
<entry>
3030
<id>facebook:post:<%= id %><%= ":#{params[:cachebuster]}" if params[:cachebuster] %></id>
3131
<title><%=
32-
if (post["live_status"] and post["live_status"] != "VOD") or post["story"][" is live now"]
32+
if (post["live_status"] && post["live_status"] != "VOD") || post["story"][" is live now"]
3333
"[LIVE] "
3434
elsif post["length"]
3535
"[#{post["length"].round.to_duration}] "
3636
end
3737
%><%=
38-
if @type == "posts" or @type == "videos"
39-
prefix = if post["live_status"] or post["story"][" live"]
38+
if @type == "posts" || @type == "videos"
39+
prefix = if post["live_status"] || post["story"][" live"]
4040
"Live"
4141
elsif %w[link video photo event].include?(post["type"])
4242
"#{post["type"].camelize}"
@@ -55,9 +55,9 @@ elsif post["description"]
5555
post["description"].to_line.truncate(120).esc
5656
end
5757

58-
if prefix and suffix
58+
if prefix && suffix
5959
"#{prefix}: #{suffix}"
60-
elsif suffix or prefix
60+
elsif suffix || prefix
6161
suffix || prefix
6262
else
6363
type.camelize
@@ -70,7 +70,7 @@ end
7070
<%= "<p><em>#{post["story"]}</em></p>".esc if post["story"] %>
7171
<%= post.slice("message", "description", "link").values.linkify_and_embed(request).to_paragraphs.esc %>
7272
<%=
73-
if type == "photo" and post["source"]
73+
if type == "photo" && post["source"]
7474
"<p><img src='#{post["source"]}' referrerpolicy='no-referrer'></p>".esc
7575
elsif type == "photo"
7676
<<~EOF.esc

‎views/index.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
</form>
7979
<% end %>
8080

81-
<% if ENV["FACEBOOK_APP_ID"] and ENV["FACEBOOK_APP_SECRET"] %>
81+
<% if ENV["FACEBOOK_APP_ID"] && ENV["FACEBOOK_APP_SECRET"] %>
8282
<form class="input-group" method="get" action="facebook">
8383
<div class="input-group-addon"><label for="facebook_q">Facebook</label></div>
8484
<input class="form-control" type="search" name="q" id="facebook_q" placeholder="Enter a Facebook page name or its url." required>

‎views/instagram_feed.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link href="https://www.instagram.com/<%= @user %>" rel="alternate" />
99
<updated><%= Time.at(@data["edge_owner_to_timeline_media"]["edges"][0]["node"]["taken_at_timestamp"]) if @data["edge_owner_to_timeline_media"]["edges"][0] %></updated>
1010
<%-
11-
if @data["is_private"] and @data["edge_owner_to_timeline_media"]["edges"].empty?
11+
if @data["is_private"] && @data["edge_owner_to_timeline_media"]["edges"].empty?
1212
reason = params[:sessionid] ? "The sessionid token is no longer valid." : "This user is private."
1313
-%>
1414

‎views/twitter_feed.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
for entity in t["extended_entities"]["media"]
2424
next if !entity["video_info"]
2525
video = entity["video_info"]["variants"].sort do |a,b|
26-
if a["content_type"].start_with?("video/") and b["content_type"].start_with?("video/")
26+
if a["content_type"].start_with?("video/") && b["content_type"].start_with?("video/")
2727
b["bitrate"] - a["bitrate"]
2828
else
2929
b["content_type"].start_with?("video/") <=> a["content_type"].start_with?("video/")

0 commit comments

Comments
 (0)
Please sign in to comment.