Lambdas & Printf

Task I Ok, another great week and I was glad that it did not require too much effort on my part, as I’ve started participating in AoC, AoCyber, and also doing Gabor Szabo’s 2022 December CI Challenge. Thus without further ado, let’s get into the code. #!/usr/bin/env python3 def bit_str(n): limit = 1 << n for i in range(limit): value = i width = f'0{n}' print(f'{value:{width}b}') if __name__ == "__main__": bit_str(2) print('\n') bit_str(3) It was a very straightforward implementation using Python & Go’s mini string formatting language.


This week’s first task is almost a continuation of task II. Task 1: Binary Flip You are given a positive integer, $n. Write a script to find the binary flip. Example 1 Input: $n = 5 Output: 2 First find the binary equivalent of the given integer, 101. Then flip the binary digits 0 -> 1 and 1 -> 0 and we get 010. So Binary 010 => Decimal 2. Example 2 Input: $n = 4 Output: 3 Decimal 4 = Binary 100 Flip 0 -> 1 and 1 -> 0, we get 011.

Reduce & Backtrack

Perl Weekly Challenge 191 Task I Another week, another opportunity to participate in the weekly Perl Challenge. The first task was self explanatory if you read the code. With use of reduce() from functools, it makes for very efficient and readable code. The logic is simple to figure out, since the sum of the n items in the list cannot be greater than the largest item. For example: Take the following list: [1, 2, 3, 4].

DFS & Backtracking

Perl Weekly Challenge 190 Task 1: Capital Detection You are given a string with alphabetic characters only: A..Z and a..z. Write a script to find out if the usage of Capital is appropriate if it satisfies at least one of the following rules: Only first letter is capital and all others are small. Every letter is small. Every letter is capital. Example 1 Input: $s = 'Perl' Output: 1 Example 2 Input: $s = 'TPF' Output: 1 Example 3 Input: $s = 'PyThon' Output: 0 Example 4 Input: $s = 'raku' Output: 1 This one was right down to the point, one simply takes the challenge rules, perform some structural pattern matching and display the result.

Secure web traffic without VPN

Using a VPN these days normally require a vendor and a possible client to route your web traffic, or to get past restrictive firewalls or to ensure that this same traffic is being watched, and that may even include your ISP. Therefore, if secure web traffic is what you want, there is an already fast, and free alternative: SOCKS5. This proxy is an SSH encrypted tunnel between a client’s application (web browser, an IRC client, etc.

The Hare Programming Language

A couple of days ago, Drew DeVault announced the release of his “secret programming” language. I have been messing around with it, and it is a joy to program with. Part of it, can be attributed to “new toy” syndrome and excitement, as I have been keeping an eye on its development. I cannot recommend it enough if you’re in the hunt for a fresh approach to a systems language. Out of the box, Hare lang gives you the essentials to get going.

The Art of RTFM

I always get asked how I know the things that I know in the UNIX/Linux world, and my reply is a very common one: RTFM. It has somewhat become a misnomer, or perhaps seen as brute way to send off newcomers to the UNIX world, but I think that this is misleading. There is an argument that it is more efficient to use a GUI browser to find the same information, and this is where I usually attempt to make my claim.

Perl Powers

Perl can replace awk, sed, and grep for most cases, specifically when a multiline regular expressions is needed. For further help with this article, perl -help is your friend. Note common Perl sigils used in this article (@: arrays/lists). For deeper understanding: sudo apt -y install perl-doc (if Debian-based distros) or sudo yum -y install perl-Pod-Perldoc (RHEL-based). Then run perldoc perlvar Common one-liner flags a split the src text into @F array (part of the -F flag) e single line expression i in place replacement (a la sed) F split the src text using a delim (a la Awk’s fields) l new line separator (’\n’ by default) p print the result & execute on each line grep replacement echo -e "foo\nfoo bar" | perl -ne 'print if /^foo$/' sed replacement echo -e "foo\nbar foo" | perl -pe 's/^f(oo)/\1/' If you want in-place replacement:

Mastering native tools in UNIX

This post is more of a reminder than anything instructional, and it stemmed from an experience I had this weekend migrating a daycare center’s website and its products entire infrastructure to the cloud. As it turned out, I was stuck on a gcloud shell with nothing but the bare tools in that box, and it solidified for me the title of this post. A lot my professional colleagues always inquire into why I use a minimal vimrc even though I also have a “full-blown” vimrc as well, or me not using great tools like ripgrep and fzf for text manipulation, or the way I set up my networking with plain ‘ol systemd service files, etc.

Alpine Linux Observations

For the past two weeks, I have been completely living under native Alpine Linux and the following are my impressions so far. For the first week, I tested the working environment (i.e. basic dotfiles, etc) while under a Debian host, and everything went as smooth as it could. I hit zero snags. With that confidence under my belt, I grabbed my old ThinkPad X220T, “torrented” the actual ISO and installed on bare-metal.

Back to top