Posts

Firefox Multi-Account Containers For The Win!

Image
How I simplified my Firefox setup with multi-account containers . TL;DR If you need multiple Firefox profiles or find yourself bombarded with unwanted ads or not sure if Facebook is tracking you around the internet then you should try Firefox and install the excellent extension Firefox Multi-Account Containers developed by the Firefox team. Not only it helps you with having a better control over your privacy but it also assists with better organising your day-to-day use of internet and have a cleaner workflow. My Internet I've been using Mozilla and then Firefox since 2002.  My one and only browser. I am a software engineer and, just like my fellow engineers around the world,  at work I do search many times a day for topics that are related to my job, like Java or Spring.  I've also got my personal topics of interests which don't necessarily overlap with those of my job, eg programming language design, history and chess. My primary e-mail is hosted on Google services, my...

Trying out Java/Scala/Groovy artefacts on the fly

There are times when you need to try out a simple snippet using a Java/Scala/Groovy artefact published on Maven central or the corporate repository. Groovy (with all its goodness ) can help you just do that without requiring you to create a dummy Maven, Gradle or SBT project. The key piece is Grape which is a " JAR dependency manager embedded into Groovy. " For example let's say you need to quickly test something with Eclipse JGit . Assuming you have already installed Groovy (eg via sdkman .), drop into the terminal and type groovysh to enter, well, the Groovy shell . // Import the Grape API we need - it's just a static method groovy:000> import static groovy.grape.Grape.grab ===> static groovy.grape.Grape.grab // Ask Grape to download the specified artefact and all its dependencies. // You may find the details for your artefact in https://mvnrepository.com groovy:000> grab(group: 'org.eclipse.jgit', module: 'org.eclipse.jgit', vers...

macOS: Open files and folders with Emacs

Image
Use Emacs to open files/folders when in Finder The first day I joined Hootsuite over a year ago, I received my work laptop; and it was a Macbook - my first ever. Naturally, as an Emacs user I needed to integrate macOS with Emacs! I wanted to be able to open files and folders in Emacs with just a keyboard shortcut. It took me some research and getting familiar with the new OS and what it offers. The result was, in macOS jargon, a "service" which I bound to command-\ . To use it, create a "Quick Action" with "automator", add a "Run Applescript" node to your workflow, copy-paste the code below and save it. You can add a keyboard shortcut to it later on, from the keyboard preferences. -- launch emacsclient in a new frame -- -- if the active application is Finder -- open the selected item(s) in a buffer(s) -- or if nothing is selected open the current directory. -- if the active application is NOT Finder -- simply create a new fra...

Python multiprocessing: Pass the shared resource along to children

Update 11 Aug '20: Turned out I misunderstood how multiprocessing module works! A Process can inherit resources created in the parent process scope but that does not include globals; ie if used_ids and used_ids_lock were defined in the block marked by if __name__ == '__main__' it would work (though not recommended). Python's documentation briefly touches upon this subject (see "Explicitly pass resources to child processes" section"). So, one correct way of structuring the code is: #!/usr/bin/env python ################################################################################ # simple tool to generate n random numbers. # # usage: # main.py N_RECORDS CONCURRENCY_STRATEGY:"t"|"p" CONCURRENCY_FACTOR:int # # N_RECORDS is an integer # CONCURRENCY_STRATEGY can only be either 't' or 'p' # CONCURRENCY_FACTOR is an integer (preferrably less than or equal to the no of # cores on the machine.) # # Examp...

Common Lisp Tips and Tricks

A collection of simple tips and tricks for the inexperienced Common Lisp programmers like myself. List (and terminate) running threads Using SBCL native functions ;; list all - mind the names CL-USER> (sb-thread:list-all-threads) (#<SB-THREAD:THREAD "main thread" RUNNING {1001878913}> #<SB-THREAD:THREAD "auto-flush-thread" RUNNING {10020BFDB3}> #<SB-THREAD:THREAD "my main loop" RUNNING {100492B8E3}> ;; this is the thread i suspect #<SB-THREAD:THREAD "reader-thread" RUNNING {1004AEFD13}> #<SB-THREAD:THREAD "swank-indentation-cache-thread" RUNNING {1004AEFE23}> #<SB-THREAD:THREAD "finalizer" RUNNING {1001E30053}> #<SB-THREAD:THREAD "repl-thread" RUNNING {10020C1BC3}> #<SB-THREAD:THREAD "control-thread" RUNNING {1004AF2853}>) ;; find the thread by name and terminate it CL-USER> (sb-thread:terminate-thread (find "my main loop...

Farewell and thank you, Plone

Image
I finally made the difficult decision of moving away from Plone+Zope stack. I've been a happy user/admin of it for almost 9 years now but I feel that I'm not able to take advantage of its offerings anymore. On the one hand, how I'm employing it has changed; whereas until a few years ago I used to host a dozen websites/portals on the very same stack -I closed that line of business a couple of years ago,- now it's only serving my own website and that of a small community of programming languages enthusiasts. A task which any simple blogging engine could do. On the other hand, even though Plone+Zope is a rock-solid stack, which requires quite minimal maintenance, my growing set of responsibilities in personal life and new priorities leaves no time for maintaining a couple of publicly available websites - those who have done so know how grave the job is. And the last downtime was hardware-related! Given the above, I decided to retire my last loyal Plone+Zope ser...

To Over or Under Engineer?

Image
In which two groups of software engineers design and implement a fly-killing machine. Once Upon A Time... Two groups of software engineers, one favouring Java and another favouring Ruby, were asked to build a device that kills the common fly.  The product is supposed to kill this nasty creature. 1 Day Later The Ruby team announced the completion of the product. "The product has gone through extensive testing. During the tests, in which we mocked the size, movement pattern and speed of the common fly, the device performed with 80% efficiency", the lead engineer commented when asked by the press about the secret to their rapid development process. A photo of the finished product by the Ruby team "Suffice to say that we had to make some design and implementation sacrifices to cut the time to market and production costs" he commented briefly on the effectiveness of the product. 367 Days Later The Java team accomplished the design of the product. "W...

Forth Interpreter and Abstract Machine

Image
Forth interpreter and abstract machine illustrated in one image. Forth has such a strikingly well thought out simple execution model that it can fit in one small diagram:

Grab Packt With Groovy

Automatically claim Packt's free e-books with a Groovy program. Introduction Packt Publishing has launched a new programme called " free learning offer "; each day they put an e-book for free on their website to download: one only needs to login to Packt's website and click on the "claim your free book" link. Following Grab Packt with Racket, here is the Groovy version, to automatically add the e-book to your Packt account for later downloads. The Code The code is in public domain. You can get it directly from is.gd/isbviw or from my github gist . For this to work you need to replace YOUR-EMAIL-ADDRESS (line 26) and YOUR-PASSWORD (line 27) with reasonable values. If you wish to run this from shell/cron remember to add #! /usr/bin/env groovy to the top of the file. The script is completely self-contained as @Grab annotation on line 4 fetches the dependencies it requires. /** * @author Bahman Movaqar */ @Grab('org.jsoup:jsoup:1.8.2') i...

Grab Packt With Racket

Automatically claim Packt's free e-books with a Racket program. Introduction Packt Publishing has launched a new programme called " free learning offer "; each day they put an e-book for free on their website to download: one needs to login to Packt's website and click on the "claim your free book" link. A nice fellow, wrote some Javascript code (nodejs) to be able to automatically claim a book, for example by calling the code from a cron job. He named the code "grab_packt" and has made it available on github . To me it is not fair to have only a Javascript version! So I decided to give it a go with different languages. This time I'll present the version written with Racket . The Code The code is in public domain. You can get it directly from is.gd/iRF96N or from my github gist . For this to work you need to replace YOUR-EMAIL-ADDRESS (line 24) and YOUR-PASSWORD (line 25) with reasonable values. If you wish to run this from shell/cron ...