Last active
August 29, 2015 14:16
-
-
Save fur-q/e41ae9d9b5a4aab3b4a6 to your computer and use it in GitHub Desktop.
imgur hilarity finder for best laughs time
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
-- $ lua imgur.lua abcde [fghij] | |
local leet = { | |
["o"] = 0, ["i"] = 1, ["e"] = 3, ["a"] = 4, ["s"] = 5, ["t"] = 7 | |
} | |
local teel = { | |
[0] = "O", [1] = "I", [3] = "E", [4] = "A", [5] = "S", [7] = "T" | |
} | |
local function upper(c) | |
if type(c) == "string" then | |
return c:upper() | |
end | |
return teel[c] or c | |
end | |
local function lower(c) | |
if type(c) == "string" then | |
return c:lower() | |
end | |
return teel[c] and teel[c]:lower() or teel[c] | |
end | |
local function imgur(word) | |
local f = io.popen("curl -s -I http://i.imgur.com/"..word..".jpg | grep Content-Length | cut -d' ' -f2") | |
local out = f:read("*l") | |
if out ~= "0\r" then | |
print("http://i.imgur.com/" .. word .. ".jpg") | |
end | |
f:close() | |
end | |
local function permute(word, n) | |
n = n or 1 | |
if n > #word then | |
imgur(table.concat(word)) | |
return | |
end | |
word[n] = upper(word[n]) | |
permute(word, n+1) | |
word[n] = lower(word[n]) | |
permute(word, n+1) | |
if leet[word[n]:lower()] then | |
word[n] = leet[word[n]:lower()] | |
permute(word, n+1) | |
end | |
end | |
local function strtot(str) | |
local out = {} | |
for i = 1, #str do | |
out[i] = string.sub(str, i, i) | |
end | |
return out | |
end | |
for _, v in ipairs(arg) do permute(strtot(v)) end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment