BingWallpapers: Fetches and applies the image of the day from Bing as the wallpaper Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Compute the day of the year“Day-of-the-week-finder”Converting image size from Maybe (Int, Int) to (Float, Float)Quote of the day programWriting values from JSON on image and display imageDay finder program, inputs date, outputs day of the weekAdvent of Code 2017 - day 8 solutionAdvent of code: day 1AoC Day 22: Sporifica Virus Part 1, a Solution in Beginner's HaskellReading and returning the HTML content from a specified URL
Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?
Should I follow up with an employee I believe overracted to a mistake I made?
Do wooden building fires get hotter than 600°C?
How do I find out the mythology and history of my Fortress?
Sum letters are not two different
Amount of permutations on an NxNxN Rubik's Cube
Why doesn't SQL Optimizer use my constraint?
Does the Weapon Master feat grant you a fighting style?
How would a mousetrap for use in space work?
Find 108 by using 3,4,6
How could we fake a moon landing now?
SF book about people trapped in a series of worlds they imagine
Is there hard evidence that the grant peer review system performs significantly better than random?
Why do we need to use the builder design pattern when we can do the same thing with setters?
Performance gap between bool std:vector and array
Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?
What is this clumpy 20-30cm high yellow-flowered plant?
What is a fractional matching?
How to compare two different files line by line in unix?
If windows 7 doesn't support WSL, then what does Linux subsystem option mean?
Should I use a zero-interest credit card for a large one-time purchase?
How to write this math term? with cases it isn't working
Why should I vote and accept answers?
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
BingWallpapers: Fetches and applies the image of the day from Bing as the wallpaper
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Compute the day of the year“Day-of-the-week-finder”Converting image size from Maybe (Int, Int) to (Float, Float)Quote of the day programWriting values from JSON on image and display imageDay finder program, inputs date, outputs day of the weekAdvent of Code 2017 - day 8 solutionAdvent of code: day 1AoC Day 22: Sporifica Virus Part 1, a Solution in Beginner's HaskellReading and returning the HTML content from a specified URL
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I have written a small desktop program nabeelomer/BingWallpapers in Haskell. This is my first time writing Haskell.
I was wondering how I can make the code use more functional programming features/idioms/patterns.
Any other suggestions on how to improve the code are also welcome.
-- Copyright (C) Nabeel Omer 2017
-- See the LICENSE file for the license
--
import Network.HTTP.Conduit
import System.Process
import qualified Data.ByteString.Lazy.Char8 as L8
import GHC.IO.Exception
main :: IO ()
main = do
-- using http://muzzammil.xyz/git/bing/
metadata <- get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
-- Guaranteed by the API
putStrLn $ (split '>' $ (lines $ L8.unpack metadata)!!1)!!1
let url = (lines $ L8.unpack metadata)!!0
picture <- get $ (split '>' url)!!1
L8.writeFile "/dev/shm/Bing-Wallpaper" picture
exitcode <- setWallpaper "/dev/shm/Bing-Wallpaper"
print exitcode
return ()
-- From StackOverflow
split :: Eq a => a -> [a] -> [[a]]
split d [] = []
split d s = x : split d (drop 1 y) where (x,y) = span (/= d) s
get :: String -> IO L8.ByteString
get url = simpleHttp url
setWallpaper :: String -> IO GHC.IO.Exception.ExitCode
setWallpaper uri = system $ "gsettings set org.gnome.desktop.background picture-uri file://" ++ uri
beginner haskell http
$endgroup$
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
$begingroup$
I have written a small desktop program nabeelomer/BingWallpapers in Haskell. This is my first time writing Haskell.
I was wondering how I can make the code use more functional programming features/idioms/patterns.
Any other suggestions on how to improve the code are also welcome.
-- Copyright (C) Nabeel Omer 2017
-- See the LICENSE file for the license
--
import Network.HTTP.Conduit
import System.Process
import qualified Data.ByteString.Lazy.Char8 as L8
import GHC.IO.Exception
main :: IO ()
main = do
-- using http://muzzammil.xyz/git/bing/
metadata <- get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
-- Guaranteed by the API
putStrLn $ (split '>' $ (lines $ L8.unpack metadata)!!1)!!1
let url = (lines $ L8.unpack metadata)!!0
picture <- get $ (split '>' url)!!1
L8.writeFile "/dev/shm/Bing-Wallpaper" picture
exitcode <- setWallpaper "/dev/shm/Bing-Wallpaper"
print exitcode
return ()
-- From StackOverflow
split :: Eq a => a -> [a] -> [[a]]
split d [] = []
split d s = x : split d (drop 1 y) where (x,y) = span (/= d) s
get :: String -> IO L8.ByteString
get url = simpleHttp url
setWallpaper :: String -> IO GHC.IO.Exception.ExitCode
setWallpaper uri = system $ "gsettings set org.gnome.desktop.background picture-uri file://" ++ uri
beginner haskell http
$endgroup$
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
$begingroup$
I have written a small desktop program nabeelomer/BingWallpapers in Haskell. This is my first time writing Haskell.
I was wondering how I can make the code use more functional programming features/idioms/patterns.
Any other suggestions on how to improve the code are also welcome.
-- Copyright (C) Nabeel Omer 2017
-- See the LICENSE file for the license
--
import Network.HTTP.Conduit
import System.Process
import qualified Data.ByteString.Lazy.Char8 as L8
import GHC.IO.Exception
main :: IO ()
main = do
-- using http://muzzammil.xyz/git/bing/
metadata <- get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
-- Guaranteed by the API
putStrLn $ (split '>' $ (lines $ L8.unpack metadata)!!1)!!1
let url = (lines $ L8.unpack metadata)!!0
picture <- get $ (split '>' url)!!1
L8.writeFile "/dev/shm/Bing-Wallpaper" picture
exitcode <- setWallpaper "/dev/shm/Bing-Wallpaper"
print exitcode
return ()
-- From StackOverflow
split :: Eq a => a -> [a] -> [[a]]
split d [] = []
split d s = x : split d (drop 1 y) where (x,y) = span (/= d) s
get :: String -> IO L8.ByteString
get url = simpleHttp url
setWallpaper :: String -> IO GHC.IO.Exception.ExitCode
setWallpaper uri = system $ "gsettings set org.gnome.desktop.background picture-uri file://" ++ uri
beginner haskell http
$endgroup$
I have written a small desktop program nabeelomer/BingWallpapers in Haskell. This is my first time writing Haskell.
I was wondering how I can make the code use more functional programming features/idioms/patterns.
Any other suggestions on how to improve the code are also welcome.
-- Copyright (C) Nabeel Omer 2017
-- See the LICENSE file for the license
--
import Network.HTTP.Conduit
import System.Process
import qualified Data.ByteString.Lazy.Char8 as L8
import GHC.IO.Exception
main :: IO ()
main = do
-- using http://muzzammil.xyz/git/bing/
metadata <- get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
-- Guaranteed by the API
putStrLn $ (split '>' $ (lines $ L8.unpack metadata)!!1)!!1
let url = (lines $ L8.unpack metadata)!!0
picture <- get $ (split '>' url)!!1
L8.writeFile "/dev/shm/Bing-Wallpaper" picture
exitcode <- setWallpaper "/dev/shm/Bing-Wallpaper"
print exitcode
return ()
-- From StackOverflow
split :: Eq a => a -> [a] -> [[a]]
split d [] = []
split d s = x : split d (drop 1 y) where (x,y) = span (/= d) s
get :: String -> IO L8.ByteString
get url = simpleHttp url
setWallpaper :: String -> IO GHC.IO.Exception.ExitCode
setWallpaper uri = system $ "gsettings set org.gnome.desktop.background picture-uri file://" ++ uri
beginner haskell http
beginner haskell http
edited Jun 26 '17 at 5:55
1 -_-
asked Jun 25 '17 at 20:38
1 -_-1 -_-
315
315
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Pattern matching instead of !!, inlining of single-use names where straightforward.
import Data.List.Split
main = do
(_:picurl:_):(_:title:_):_ <- map (wordsBy (=='>')) . lines . L8.unpack
<$> get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
putStrLn title
L8.writeFile "/dev/shm/Bing-Wallpaper" =<< get picurl
print =<< setWallpaper "/dev/shm/Bing-Wallpaper"
$endgroup$
$begingroup$
Can you please explain how themap (wordsBy (=='>')) . lines . L8.unpack <$> getpart works?
$endgroup$
– 1 -_-
Jun 27 '17 at 19:08
$begingroup$
(<$>) :: Functor f => (a -> b) -> f a -> f bis an infix synonym forfmap, andfmap f xis likex >>= return . ffor monads.mapappliesData.List.Split's wording ofsplitto both lines where you'd do it to each manually.(f . g) x = f (g x)and.has higher precedence than<$>, so all of the left of<$>isfmaped over its right. Feel free to keep your comments around, of course.
$endgroup$
– Gurkenglas
Jun 27 '17 at 21:08
1
$begingroup$
You have presented an alternative solution, but only slightly reviewed the code. Please explain your reasoning (how your solution works and why it is better than the original) in the post, not in the comments, so that the author and other readers can learn from your thought process.
$endgroup$
– Zeta
Jun 29 '17 at 7:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f166622%2fbingwallpapers-fetches-and-applies-the-image-of-the-day-from-bing-as-the-wallpa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Pattern matching instead of !!, inlining of single-use names where straightforward.
import Data.List.Split
main = do
(_:picurl:_):(_:title:_):_ <- map (wordsBy (=='>')) . lines . L8.unpack
<$> get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
putStrLn title
L8.writeFile "/dev/shm/Bing-Wallpaper" =<< get picurl
print =<< setWallpaper "/dev/shm/Bing-Wallpaper"
$endgroup$
$begingroup$
Can you please explain how themap (wordsBy (=='>')) . lines . L8.unpack <$> getpart works?
$endgroup$
– 1 -_-
Jun 27 '17 at 19:08
$begingroup$
(<$>) :: Functor f => (a -> b) -> f a -> f bis an infix synonym forfmap, andfmap f xis likex >>= return . ffor monads.mapappliesData.List.Split's wording ofsplitto both lines where you'd do it to each manually.(f . g) x = f (g x)and.has higher precedence than<$>, so all of the left of<$>isfmaped over its right. Feel free to keep your comments around, of course.
$endgroup$
– Gurkenglas
Jun 27 '17 at 21:08
1
$begingroup$
You have presented an alternative solution, but only slightly reviewed the code. Please explain your reasoning (how your solution works and why it is better than the original) in the post, not in the comments, so that the author and other readers can learn from your thought process.
$endgroup$
– Zeta
Jun 29 '17 at 7:05
add a comment |
$begingroup$
Pattern matching instead of !!, inlining of single-use names where straightforward.
import Data.List.Split
main = do
(_:picurl:_):(_:title:_):_ <- map (wordsBy (=='>')) . lines . L8.unpack
<$> get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
putStrLn title
L8.writeFile "/dev/shm/Bing-Wallpaper" =<< get picurl
print =<< setWallpaper "/dev/shm/Bing-Wallpaper"
$endgroup$
$begingroup$
Can you please explain how themap (wordsBy (=='>')) . lines . L8.unpack <$> getpart works?
$endgroup$
– 1 -_-
Jun 27 '17 at 19:08
$begingroup$
(<$>) :: Functor f => (a -> b) -> f a -> f bis an infix synonym forfmap, andfmap f xis likex >>= return . ffor monads.mapappliesData.List.Split's wording ofsplitto both lines where you'd do it to each manually.(f . g) x = f (g x)and.has higher precedence than<$>, so all of the left of<$>isfmaped over its right. Feel free to keep your comments around, of course.
$endgroup$
– Gurkenglas
Jun 27 '17 at 21:08
1
$begingroup$
You have presented an alternative solution, but only slightly reviewed the code. Please explain your reasoning (how your solution works and why it is better than the original) in the post, not in the comments, so that the author and other readers can learn from your thought process.
$endgroup$
– Zeta
Jun 29 '17 at 7:05
add a comment |
$begingroup$
Pattern matching instead of !!, inlining of single-use names where straightforward.
import Data.List.Split
main = do
(_:picurl:_):(_:title:_):_ <- map (wordsBy (=='>')) . lines . L8.unpack
<$> get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
putStrLn title
L8.writeFile "/dev/shm/Bing-Wallpaper" =<< get picurl
print =<< setWallpaper "/dev/shm/Bing-Wallpaper"
$endgroup$
Pattern matching instead of !!, inlining of single-use names where straightforward.
import Data.List.Split
main = do
(_:picurl:_):(_:title:_):_ <- map (wordsBy (=='>')) . lines . L8.unpack
<$> get "http://cdn.muzzammil.xyz/bing/bing.php?format=text&cc=IN"
putStrLn title
L8.writeFile "/dev/shm/Bing-Wallpaper" =<< get picurl
print =<< setWallpaper "/dev/shm/Bing-Wallpaper"
answered Jun 27 '17 at 13:53
GurkenglasGurkenglas
2,967512
2,967512
$begingroup$
Can you please explain how themap (wordsBy (=='>')) . lines . L8.unpack <$> getpart works?
$endgroup$
– 1 -_-
Jun 27 '17 at 19:08
$begingroup$
(<$>) :: Functor f => (a -> b) -> f a -> f bis an infix synonym forfmap, andfmap f xis likex >>= return . ffor monads.mapappliesData.List.Split's wording ofsplitto both lines where you'd do it to each manually.(f . g) x = f (g x)and.has higher precedence than<$>, so all of the left of<$>isfmaped over its right. Feel free to keep your comments around, of course.
$endgroup$
– Gurkenglas
Jun 27 '17 at 21:08
1
$begingroup$
You have presented an alternative solution, but only slightly reviewed the code. Please explain your reasoning (how your solution works and why it is better than the original) in the post, not in the comments, so that the author and other readers can learn from your thought process.
$endgroup$
– Zeta
Jun 29 '17 at 7:05
add a comment |
$begingroup$
Can you please explain how themap (wordsBy (=='>')) . lines . L8.unpack <$> getpart works?
$endgroup$
– 1 -_-
Jun 27 '17 at 19:08
$begingroup$
(<$>) :: Functor f => (a -> b) -> f a -> f bis an infix synonym forfmap, andfmap f xis likex >>= return . ffor monads.mapappliesData.List.Split's wording ofsplitto both lines where you'd do it to each manually.(f . g) x = f (g x)and.has higher precedence than<$>, so all of the left of<$>isfmaped over its right. Feel free to keep your comments around, of course.
$endgroup$
– Gurkenglas
Jun 27 '17 at 21:08
1
$begingroup$
You have presented an alternative solution, but only slightly reviewed the code. Please explain your reasoning (how your solution works and why it is better than the original) in the post, not in the comments, so that the author and other readers can learn from your thought process.
$endgroup$
– Zeta
Jun 29 '17 at 7:05
$begingroup$
Can you please explain how the
map (wordsBy (=='>')) . lines . L8.unpack <$> get part works?$endgroup$
– 1 -_-
Jun 27 '17 at 19:08
$begingroup$
Can you please explain how the
map (wordsBy (=='>')) . lines . L8.unpack <$> get part works?$endgroup$
– 1 -_-
Jun 27 '17 at 19:08
$begingroup$
(<$>) :: Functor f => (a -> b) -> f a -> f b is an infix synonym for fmap, and fmap f x is like x >>= return . f for monads. map applies Data.List.Split's wording of split to both lines where you'd do it to each manually. (f . g) x = f (g x) and . has higher precedence than <$>, so all of the left of <$> is fmaped over its right. Feel free to keep your comments around, of course.$endgroup$
– Gurkenglas
Jun 27 '17 at 21:08
$begingroup$
(<$>) :: Functor f => (a -> b) -> f a -> f b is an infix synonym for fmap, and fmap f x is like x >>= return . f for monads. map applies Data.List.Split's wording of split to both lines where you'd do it to each manually. (f . g) x = f (g x) and . has higher precedence than <$>, so all of the left of <$> is fmaped over its right. Feel free to keep your comments around, of course.$endgroup$
– Gurkenglas
Jun 27 '17 at 21:08
1
1
$begingroup$
You have presented an alternative solution, but only slightly reviewed the code. Please explain your reasoning (how your solution works and why it is better than the original) in the post, not in the comments, so that the author and other readers can learn from your thought process.
$endgroup$
– Zeta
Jun 29 '17 at 7:05
$begingroup$
You have presented an alternative solution, but only slightly reviewed the code. Please explain your reasoning (how your solution works and why it is better than the original) in the post, not in the comments, so that the author and other readers can learn from your thought process.
$endgroup$
– Zeta
Jun 29 '17 at 7:05
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f166622%2fbingwallpapers-fetches-and-applies-the-image-of-the-day-from-bing-as-the-wallpa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown