Better alternative for PHP sleep: use a dotted progress bar with Javascript
From PHP sleep to Javascript setInterval, choosing the best tool for the job to create a visual dotted progress bar in the browser.
From PHP sleep to Javascript setInterval, choosing the best tool for the job to create a visual dotted progress bar in the browser.
In this post I show you how to write a Python script to send a weekly newsletter out of now_playing, upcoming, top_rated, and popular movies, using the themoviedb API
Don't miss any book! Using Python/ BeautifulSoup I scrape Safaribooks' recently added page and create a daily (cron) notification email. This pre-work led to me writing my first Twitter bot @newsafaribooks
My meta-post on reading. In this post a couple of tools to better retain info, and some tricks to get more reading done. "Books are a uniquely portable magic." (Stephen King)
We buy things we don't need, to impress people we don't like.
Tyler Durden (Fight Club)
I just finished Essentialism: The Disciplined Pursuit of Less. Here are some things to ponder over:
- A lot of essentialism is to become focussed on what matters most. This takes practice. One good advice I found in the book is to ask yourself the following question while doing any particular task: “Is this the very most important thing I should be doing with my time and resources right now?” or “Will this activity or effort make the highest possible contribution towards my goal?”
- Define what you want and prioritise your life. Not doing this has a double cost: not only will you not advance, you also are subjected to the whims of other people who will plan your life for you.
- The Essentialist thinks in: “I choose to,” “Only a few things really matter,” and “I can do anything but not everything.”
- Learn to say NO. There is always too much to do, read, learn. However only a few things matter. Watch out for the trap of “decision fatigue”: the more choices we are forced to make, the more the quality of our decisions deteriorates. As Derek Sivers says: No more yes. It's either HELL YEAH! or no.
- The importance of sleep. Sleep is the driver of peak performance. Lack of sleep has a detrimental effect on your health and productivity: you cannot think clearly, you cannot prioritise (fundamental essentialist skill!). To learn more about the science of sleep, check out Night School (Richard Wiseman).
- Disconnect. The book states "We need space to escape in order to discern the essential few from the trivial many.” - too much routine and we get stuck. Sometimes we have to step outside. You remember how clear your mind was after that last trip abroad?
- Less is more. These days we have more information, but less knowledge. Quality lays in doing a few things very well, rather than a lot of things half-assed.
- Essentialism is not about how to get more things done; it’s about how to get the right things done. As Stephen R. Covey said: “If the ladder is not leaning against the right wall, every step we take just gets us to the wrong place faster.”
- To advance in your career it usually boils down to: “What would happen if we could figure out the one thing you could do that would make the highest contribution?” - usually there is one or a few critical things, spot them. Use Pareto’s principle to guide you: what 20% of the effort is producing 80% of the results? Further reading: The 80/20 Principle by Richard Koch.
- Eliminate. Essentialists invest the time they have saved into creating a system for removing obstacles and making execution as easy as possible. One trap the book describes is our sunk-cost bias: "studies have found that we tend to value things we already own more highly than they are worth and thus that we find them more difficult to get rid of". Elimination is not only limited to material things. We should avoid time wasters, automate, and delegate where possible. Refer to the 4 hour work week for practical advice.
- Lack inspiration what to work on next? The books gives us 3 questions for determining where to put our time and effort towards: “What do I feel deeply inspired by?”, “What am I particularly talented at?” and “What meets a significant need in the world?”. For me similar questioning led to prefer a career in Software Development over Finance (my degree) = passion, talent and market demand combined.
- "Every day do something that will inch you closer to a better tomorrow.” said Doug Firebaugh. How do you eat an elephant? One bite at a time. Long term goals may seem overwhelming. Building an Android app with little experience surely was for me. Yet, when dividing it in subtasks (small wins), the app came to life and I was surprised how fast it was coming along. Moreover, small wins create momentum, you become unstoppable. Same with getting into physical shape: it does not happen overnight, but putting the disciplined work in every day you start to see significant results soon and you just keep going. Persistence and repetition are very powerful skills!
Essentialist quotes
“Tell me, what is it you plan to do / with your one wild and precious life?”
- Mary Oliver“You cannot overestimate the unimportance of practically everything.”
- John MaxwellA non-Essentialist thinks almost everything is essential. An Essentialist thinks almost everything is non-essential.
- Greg Mckeown (link contains other quotes from the book)"I do believe in simplicity. It is astonishing as well as sad, how many trivial affairs even the wisest
thinks he must attend to in a day; how singular an affair he thinks he must omit. When the mathematician would
solve a difficult problem, he first frees the equation of all incumbrances, and reduces it to its simplest terms.
So simplify the problem of life, distinguish the necessary and the real.
Probe the earth to see where your main roots run."
- Henry David Thoreau“People are effective because they say ‘no,’ because they say, ‘this isn’t for me’.”
- Peter Drucker“If one's life is simple, contentment has to come. Simplicity is extremely important for happiness.
Having few desires, feeling satisfied with what you have, is very vital: satisfaction with just enough food,
clothing, and shelter to protect yourself from the elements. And finally, there is an intense delight in
abandoning faulty states of mind and in cultivating helpful ones in meditation.”
- Dalai Lama
I just finished Android 1: Introduction to Mobile Application Development (O'Reilly School of Technology). For the final project you had to build a complete app. One of the options was the Hangman game. This was quite a challenge being new to Android programming and games.
But I took it and I managed to do it, the result is Free Monkey, my implementation of Hangman. No casualties though, I changed the theme to be more gentle: you have to prevent an innocent monkey to get locked in. If you guess the right word he is set free and can eat his banana too:
This is much more fun than a hanging poor fellow, game development is a creative skill as well :)
The game is simple but has all the necessary features: multiple themes (cities, famous people, movies, music, books), 5 levels with increasing difficulty (last 2 levels have a timer), 1 hint per game and a point-gaining/bonus system.
The game is in English and Spanish (however the words are mostly in English). And unlike other Hangman games I played you don't get interrupted by annoying ads and popups :)
You can read the details in the readme.
1 hint per game, Spanish / English interface, button pad to quickly enter letters
you win: monkey is set free and even gets food, more bonus the better/harder you play
] you loose: monkey locked in, no worries: just click on New Game and keep trying
The game can be installed from Google Play. If you like word guessing games, give it a try and let me know what you think. Your feedback is invaluable to me as I am learning both Android and game development.
Have fun!
fI am reading a book on VimL (Vimscript) and it introduced me to mpc, a client for Music Player Daemon (MPD) . In this post I show you how to set up mpc and how to quickly select and play music from the command line.
After getting the two with brew install mpc / mpd, you define where your music lives:
$ cat ~/.mpdconf bind_to_address "127.0.0.1" music_directory "/Users/bbelderb/Music/" db_file "/Users/bbelderb/Music/mpd.db" audio_output { name "audio" type "osx" }
And you create the DB file:
$ touch ~/Music/mpd.db
Then you can start playing music with:
$ mpc update $ mpc ls | mpc add $ mpc play
(use "listall" instead of "ls" if you have subdirectories in your defined music_directory)
Now I wondered how to quickly search for songs and play the search result.
I ended up adding this to my .bashrc:
alias mp="mpc toggle" # handy to quickly stop / resume music alias mn="mpc next" function ms() { mpc search any $1; } function mss() { mpc clear 2>&1 >/dev/null && mpc search any $1|mpc add && mpc play; }
Note the difference between ms and mss: former just lists search results, the latter plays them as a new playlist. Thanks to this StackExchange thread.
So now if I want to play something specific I can do so pretty quickly (of course my options are limited to the music in the defined music_directory):
$ mpc stats Artists: 66 Albums: 6 Songs: 120 ..
# list search results $ ms tony timferriss/timferrissshow-tonyrobbins-pt1.mp3 timferriss/timferrissshow-tonyrobbins-pt2.mp3 # same, but play them as well $ mss tony Tim Ferriss: Bestselling Author, Human Guinea Pig - Tony Robbins on Morning Routines, Peak Performance & Mastering Money - Part 1 of 2 [playing] #1/2 0:00/68:20 (0%) # create new playlist on-the-fly, searching for "roni" (of Roni Size) # result: a new playlist of 6 hits plays:
$ mss roni Roni Size - It's Jazzy (Nu:Tone Remix) [playing] #1/6 0:00/6:06 (0%)
How to Fail at Almost Everything and Still Win Big is Scott Adams' (creator of Dilbert) funny memoir about his many failures and what they taught him about success.
I enjoyed this entertaining page-tuner. There are many useful lessons in this book, just a couple:
- Have a system instead of goals. A goal is something specific you achieve or not, systems however refer to things you do on a regular basis that increase your odds of happiness. Systems for me are: diet + exercise, reading, writing, parenting, and coding.
- To find out where your talent lies, remember what you were doing obsessively by the age of ten. In my case it was painting and building stuff with Lego. This explains my interest in designing websites and building software.
- Don't fear failure, embrace it. As you read through Scott's many failures you discover how much he learned and how it all contributed to later successes.
- Try a lot of different things (sampling), bail out if you don't see results. The more you try, the greater the odds you stumble upon a successful idea. Scott reveals his Success Formula: Every Skill You Acquire Doubles Your Odds of Success. The more concepts you understand, the easier you learn new stuff.
- Achievers see success as a skill that can be learned. That means they figure out what they need and they go and get it.
- Learn essential skills like writing, psychology (cognitive biases), conversation, persuasion and technology.
- Don’t assume you know how much potential you have. Sometimes the only way to know what you can do is to test yourself.
- The biggest component of luck is timing. Samuel Goldwyn said "The harder I work, the luckier I get."
- Proper eating and exercise form the corner stone for further success.
- Books change us automatically, just as any experience does.
2014 was a good year: I certified in both Python and Java at the O'Reilly school of technology, I attended GDG devfest (Amsterdam) which was an inspiring event, and I became a healthy programmer by adding exercise and good dieting practices to my daily habits.
Now 2015 is here. I am not really a New Year's resolutions guy, but this year I want to define some goals:
- read an average of one book per week. No need to expand ... reading makes you a better human being. My Reading List
- build an Android app. Mobile and Android are hot, you could argue that iOS is better etc., but you have to start somewhere.
- build an app with the MEAN (MongoDB, Express, Angular, Node.js) stack. Javascript is everywhere, good to get more skilled in it. If time, add Dart and web components.
- get basic skills in data science (big data) and related: certify in Advanced Java (O'Reilly School - includes an algorithm module)
I need to get back to blogging. It will happen, and then I will update on above topics.
Happy 2015!
- Bob
A little programming exercise to keep the coder alive ... Problem: DJ Marky's podcast gone in iTunes. Suggested fix: batch-download podcast feed. Requirement: 140 characters ("golf") solution to tweet it around ... no seriously: I wanted to see how to solve this in a nice one-liner (so no fancy input options for this script ... google on: 'script download podcast feed <your preferred coding tool>' for more advanced stuff already out there).
This is what I have come up with so far:
wget $(wget -q -O - feed_url | sed -n 's/.*enclosure.*url="\([^"]*\)" .*//p')
Read this from the inside-out: get the feed and dump to standard output (-O) and without other noise (-q), filter the enclosure tags and get the URL out of it (the enclosure tag is what the feeds have in common. See the RSS spec). This is wrapped in a subprocess ( $(...) ) and provides a list of mp3 files which is fed to the outer wget which starts to download them one by one.
Although I tend to use perl -pe in one-liners for its powerful regex engine, I learned the useful -n / p combo of sed to combine grep and replacing strings in one go (suggestions in perl are welcome in the comments ...)
Extending it to a small script to receive a feed as input as first command line argument ($1):
podcast_feed.sh
#!/bin/bash wget $(wget -q -O - $1 | sed -n 's/.*enclosure.*url="\([^"]*\)" .*//p')
Testing a 'dry run' (don't download / print-only) version with various feeds (just take the outer wget off)
podcast_feed_print.sh
#!/bin/bash wget -q -O - $1 | sed -n 's/.*enclosure.*url="\([^"]*\)" .*/# /p'
Test it with 5 feeds:
$ for pc in $(cat podcast_feed_test.txt);
> do echo "testing "$pc && ./podcast_feed_print.sh $pc | head -2 && echo
> done
testing http://djmarky.com.br/podcast/podcast.xml # http://p.audio.uol.com.br/djmarky/podcast/markys_podcast_august_2013.mp3 # http://p.audio.uol.com.br/djmarky/podcast/marky_july_2013.mp3 testing http://feeds.feedburner.com/spipodcast # http://traffic.libsyn.com/patflynn/SPI092-Psychology_of_Selling_How_to_Price.mp3 # http://traffic.libsyn.com/patflynn/SPI091-Mixing_Online_Business_with_Offline_Marketing_Strategies.mp3 testing http://www.fatburningman.com/feed/podcast/ # http://traffic.libsyn.com/fatburningman/99DrDavidPerlmutter.mp3 # http://traffic.libsyn.com/fatburningman/98ChrisKresser.mp3 testing http://lewishowes.com/feed/podcast/ # http://media.blubrry.com/the_school_of_greatness/www.podtrac.com/pts/redirect.mp3/feeds.soundcloud.com/stream/126379015-lewishowes-sean-stephenson-how-to-leave.mp3 # http://media.blubrry.com/the_school_of_greatness/www.podtrac.com/pts/redirect.mp3/feeds.soundcloud.com/stream/124890483-lewishowes-daniel-negreanu.mp3 testing http://feeds.feedburner.com/se-radio # http://feedproxy.google.com/~r/se-radio/~5/mqwgeoTD1sc/SE-RadioEpisode199-MichaelStonebraker.mp3 # http://feedproxy.google.com/~r/se-radio/~5/rcNWFPGdwrk/SE-RadioEpisode198-WilVanDerAalst.mp3
Works, and with 86 characters quite small!
Downloading podcasts now ...
$ podcast_feed.sh http://djmarky.com.br/podcast/podcast.xml --2013-12-27 00:46:35-- http://p.audio.uol.com.br/djmarky/podcast/markys_podcast_august_2013.mp3 Resolving p.audio.uol.com.br... 200.147.98.177, 200.147.1.156, 200.147.1.157, ... Connecting to p.audio.uol.com.br|200.147.98.177|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 89803694 (86M) [audio/mpeg] Saving to: ‘markys_podcast_august_2013.mp3’ .. ..
The code used in this post can be found here.