What did you learn today?
New postTIL in Ruby: `arity`
by @rinas
Returns the number of mandatory arguments.
If the block is declared to take no arguments, returns 0.
If the block is known to take exactly n arguments, returns n.
If the block has optional arguments, returns -n-1
TIL what bare git repositories and git worktrees are
by @ilango

A bare repo, doesn't have our project files and only has the folders and files in the above image. When we clone a repo, if we add `--bare` to the clone command, we make a bare repo.
Why do this?
For one, we can clone off of a bare repo:
git clone --bare /home/ilango/aurelius aurelius_2
Note that the I'm cloning a repo from a local folder. This is useful for collaboration when we have a shared storage in a local network and don't want to host our project in the cloud.
What made me more interested in bare repos is worktrees. Git worktrees are one of the lesser known but coolest features. It allows us to have unfinished work in multiple branches at the same time, without having to use `git stash`.
For example, let's say you're in `feature-branch-1`, and are made aware of a bug in `main`. You have unstaged work in feature-branch-1, so you run `git stash`, checkout to main, fix the bug, come back to the feature branch and run `git stash pop`. With worktrees, we don't need to do all this.
Instead of a normal clone, do a bare clone, and run
git worktree add main main
Note: first "main" is the folder name, second "main" is the branch name. Also note, the main folder in the image. That's my main branch worktree.
This creates a main folder in your bare repo. Changing to this repo we can see that the main folder contains our main branch! We can do this for as many branches as we want and switch between them with different changes. We don't need bare repositories for using git worktrees but it keeps my folder structure cleaner.
More details here: https://git-scm.com/docs/git-worktree
GitHub has a "template repository" feature
by @mzrnsh
It's located right under the project name in settings, and once on, a new green button "Use this template" appears on repository home page. You can see it in action on my Jekyll+Tailwind boilerplate: https://github.com/mzrnsh/jekyllwind
TIL in Golang: Identifying Isograms & difference of squares
by @ilango
After I finished them, I checked the community solutions and realized how brute-forced, inefficient my solution was. But that's the process of learning.
By checking community solutions, I learned about two methods available in the standard library: IsLetter and ContainsRune!
TIL in Golang: Time, Type Conversion & Assertion, First class functions
by @ilango
Fortunately, time was the last concept I had to learn in the Go syllabus on Exercism. Now on to the other exercises, 1 or 2 a day. Also, it's time to dive into some projects from this project-based learning repo: https://github.com/practical-tutorials/project-based-learning#go
*SPOILERS*
Time: https://exercism.org/tracks/go/exercises/booking-up-for-beauty/solutions/ilango
Type Conversion & Assertion: https://exercism.org/tracks/go/exercises/sorting-room/solutions/ilango
First class functions: https://exercism.org/tracks/go/exercises/expenses/solutions/ilango
TIL in Flutter, we can specify the app version and build number in pubspec.yaml
by @rinas

TIL in Golang: Interfaces & Errors
by @ilango
So there is no exceptions for error handling in Go. Instead errors are values of an interface called `error`. In order to learn errors, I had to learn interfaces.
I still need more practice on these two topics because I feel my understanding of them is a bit shaky. Anyways, here's my solution:
*SPOILERS*
https://exercism.org/tracks/go/exercises/the-farm/solutions/ilango
TIL in Javascript, Date `getMonth()` does not give the correct month as we expect 🤯
by @rinas
today = new Date() Thu May 05 2022 19:28:34 GMT+0530 (India Standard Time) today.getMonth() 4
what! it should be 5 (May!)
looks like the return values are from 0 to 11
so for now we'll have to do today.getMonth() + 1 to get correct month value
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth#return_value
Netlify serves Jekyll 404 pages out of box
by @mzrnsh
Well, today I learned that Netlify respects our time as well and placing a `404.html` page in the root will also work magically over there, with 0 config.
TIL in Golang: Regular Expressions
by @ilango
The exercise is parsing logs and cleaning up logs. We have to write a bunch of functions that does different cleaning up and organizing tasks.
*SPOILERS*
Solution: https://exercism.org/tracks/go/exercises/parsing-log-files/solutions/lbcosta
TIL in Golang: Methods & Runes
by @ilango
Pretty simple exercises but took me a bit of time to figure out a few issues, especially in runes.
*SPOILERS*
Runes: https://exercism.org/tracks/go/exercises/logs-logs-logs/solutions/ilango
Methods: https://exercism.org/tracks/go/exercises/elons-toys/solutions/ilango
TIL in Golang: Pointers
by @ilango
Anyways, today's Golang lesson was Pointers. The exercise was to build a simplified digital vote counting system for a students' association president election.
Here's my solution (SPOILERS): https://exercism.org/tracks/go/exercises/election-day/solutions/ilango
TIL in Golang: Range Iteration & Type Definitions
by @ilango
Today's lessons were Range Iteration and Type Definitions. Both have a common exercise, which was to generate a simple chessboard and do small calculations on it.
Here's my solution (SPOILERS): https://exercism.org/tracks/go/exercises/chessboard/solutions/ilango
TIL we can compare versions in Ruby using `Gem::Version` without any gems
by @rinas
Gem::Version.new('1.0.1') > Gem::Version.new('1.0.0')
Here is the link to the documentation: https://ruby-doc.org/stdlib-3.1.0/libdoc/rubygems/rdoc/Gem/Version.html
How to add images to a README.md file
SimpleHTTPServer has become even simpler in Python 3
by @mzrnsh
python -m SimpleHTTPServer 8000
Today I learned that the command has become a bit more memorable in Python 3:
python3 -m http.server
TIL How to change screenshot directory in macOS
by @rinas
defaults write com.apple.screencapture location {location here}
e.g,
defaults write com.apple.screencapture location /Users/rinas/Desktop/Screenshots
TIL in Rails: Code after redirect_to gets executed
by @rinas
redirect_to url and return
Here is the issue which talks about this: https://github.com/rails/rails/issues/26363
TIL about using counter_cache in rails to save association's count in parent model
by @rinas
Here is the SO answer that helped: https://stackoverflow.com/a/16996960/3098242

TIL about beginless and endless ranges in Ruby
# Users with an ID less than or equal to 200. User.where("id <= ?", 200) User.where(id: ..200) # Users with an ID less than 200. User.where("id < ?", 200) User.where(id: ...200) # Users with an ID greater than or equal to 200. User.where("id >= ?", 200) User.where(id: 200..)
TIL how to select values from one column without `nil` in Rails
by @rinas
Page.where.not(custom_domain: nil).pluck(:custom_domain)
---------------------------------------
Page.pluck(:custom_domain)

`.pluck` picks values but includes `nil` as well. So we can use `.compact`
Page.pluck(:custom_domain).compact

TIL what policy to use for AWS S3 to work with Rails Active Storage
by @rinas

TIL how to colour console logs
by @rinas
console.log('%c hey red text', 'color: red') console.log('%c hey green text', 'color: green')
