Thursday, 14 December 2017

When I want to buy a shirt I write a shell script

Problem

I want to buy a shirt. It's a beautiful one. But unfortunately it is unavailable in my size. I need a solution that checks the product page regularly and notifies me when the shirt is available.

Input

The URL of the product page.

Output

Some kind of notification that lets me know my shirt is available.

Constraints

Don't spend more than a few minutes on this, write a throw-away solution. It doesn't need to be fool-proof or portable. Environment is cygwin.

Solution

Anything more than a simple shell script feels like an overkill. The notification can't be email because I have no access to an smtp server, let's use 'cygstart url'; it will open the product page in a browser. Wouldn't be acceptable if, for example, I used this computer for presentations, but it's a good solution in this case.
The script's first parameter is the product page including the product-specific query string, the second parameter is a html fragment that represents the product on that page.
#!/bin/sh

URL=$1
FRAGMENT=$2
 
while true; do
    NUM=`curl -s $URL | grep "$FRAGMENT" | wc -l`
    if [ "$NUM" -gt 0 ]
       then
           cygstart "$URL" 
           exit
       fi
    sleep 60m
done

Tuesday, 21 March 2017

About the JavaScript community

JavaSrcipt is a very capable and in many ways a beautiful language. I love the good parts of it, especially when it is used in FP style. I can't say the same about the community. It's the kind of community that demands adding classical OO and classical inheritance to a language that had a completely different philosophy. It's the kind of community that doesn't care about the soul of a language. I don't think OO or classical inheritance has anything good to do in ES6.
I also don't think it is a good idea that you are supposed to orchestrate minimum half a dozen of tools for "modern JavaScript programming". I also don't believe that anyone in their sane mind could reason for 600 node modules when I scaffold a chrome extension project with yeoman (generator-chrome-extension). Of which modules I looked at two; one of them was a one-liner, the other one started with the comment "this entire module is depressing". For the same reason I can't be impressed by the exponential growth of the npm modules, because, well, most of that is garbage.
www.modulecounts.com
The majority of the JavaScript community are still the same copy-paste-i-dont-understand-what-i-am-doing-and-ask-basic-questions-on-stackoverflow guys as it was ten years ago. Actually it feels like the sole purpose of all these tools is to make copy-paste manageable on the enterprise level.

Wednesday, 7 December 2016

You don't speak JavaScript

For some reason JavaScript is a language that even top programmers are not willing to learn and understand properly.
Joe Armstrong. The father of the Erlang language. The language that has concurrency in its core. I've just finished reading an article of Mr Armstrong in which he compares JavaScript's concurrency to Erlang's. Now, what can we expect from The Average JavaScript Programmer if this is what I've read?

You write something like this:
    var done  = function(x){ ... do something with x ..};
    var error = function(x){ .... x ...}
    read(Something, {onSuccess:done, onError:error});
    ...
    ... more code ...
Code like this melts my brain.

When the program is executing somewhere inside “_more code_”, the read completes, and I'm time warped back in time to the code in _done_, then back to wherever I came from in “_more code_” when _done_ completes. I find this very difficult to understand.
...
But what happens if an event is triggered in the time interval between removing an event handler and adding a new one.
... 
source

No Mr Armstrong. That is not how JavaScript callbacks are executed :(

Tuesday, 22 November 2016

"Branches" in git

Sometimes people want to see "branches" in git. They come to you and say Show me please the master branch. What they want to see is the commits that !at the time when they were created! were pointed to by the master reference. And when, for example at the time of master-dev merge, all you have is this:
o  <- master, dev
| \
o  o
...
Then you are like

But if you consistently apply a small tweak and instead of the usual workflow:
git checkout dev
git merge master
git checkout master
git merge dev
#this is a simplified process;
#there are pulls happening there
#optionally temp merge branches created
#conflicts resolved...
#but those are irrelevant here
You do:
git checkout dev
git merge master
git checkout master
git merge --no-ff dev
Now that small change gives us a graph like this:
o  <- master
| \
|  o  <- dev
| /|
o  |  (<- master^)
|  |
o  |  (<- master^^)
|  o  (<- dev^)
...

The benefits are: when you use UI tools to visualise the git log, those tools almost certainly keep the master branch in a nice straight line through all these merges. And from the command line you have the option
git log --first-parent master
And there it is: a "master branch"!

Saturday, 10 September 2016

Embrace the platform

Instead of building with tools, and using all of these tools to build our website and we ship all the tools to our users, essentially. What if we would write using the primitives on the web and then what the users get is just a slightly augmented version of that depending what their browser support. So it's like our tools become part of our deploy process, but not part of our development process.

Thursday, 2 June 2016

Clojure code browser in Emacs

A post from ProDevTips blog landed in my feed reader through PlanetClojure's RSS feed describing a custom-developed Clojure function browser in Emacs. I just wanted to post a simpler, built-in solution because I had this in my configuration and I find it a really neat feature. First, here is the end result:
Clojure function browser in Emacs
The package that does the magic is speedbar and sr-speedbar. Speedbar is a built-in feature of Emacs, the sr-speedbar package embeds speedbar in the buffer's frame, because otherwise it opens in a new frame. And to make speedbar work with Clojure you need this in your init file:
(require 'speedbar)
(speedbar-add-supported-extension ".clj")
For me this worked out-of-the-box, but I think it relies on one of the Clojure or programming packages I configured earlier. Here is the list of my packages that I think can be related:
  • cider
  • ac-cider
  • clojure-mode
  • projectile
  • company