My learning diary

Sticky

I found myself entangled in CSS. I needed app-header to stick to the top at all times. I also needed template-header to be right beneath app-header at all times. Lastly, embedded-content should begin immediately after template-header and should not be sticky. Here’s how the page organisation might look like: <div class="app"> <div class="app-header"> <!-- Content --> </div> <div class="app-content"> <div class="template-container"> <div class="template-header"> <!-- Content --> </div> <div class="embedded-content"> <!-- Content --> </div> </div> </div> </div> The simplest approach is to place app-header and template-header inside a single div.

Continue reading "Sticky"

Iterator to Stream

With Google Guava, you can transform an Iterator into a Stream with Streams.stream(...). But that API is only available from Guava 21. If you don’t want to use Guava or if your Guava version is below 21, you need an additional step to convert your Iterator to a Stream: Stream<String> stream = StreamSupport.stream( Spliterators.spliteratorUnknownSize( iterator, Spliterator.ORDERED ), false ); Reference: mkyong.

Continue reading "Iterator to Stream"

reCaptcha on-error

Polling wasn’t effective because: Hot reloading did not happen because of some heap limit error. I called the wrong function to check if the reCaptcha errored. To deal with the heap limit, my buddy suggested updating the docker-dev script in package.json to: { "scripts": { "docker-dev": "export NODE_OPTIONS=\"--max-old-space-size=4096\" && ..." } } As for checking if the reCaptcha errored, neither on-expire nor captchaService.isValid worked. A possible explanation for the former would be that the reCaptcha didn’t expire.

Continue reading "reCaptcha on-error"

pip uninstall All

I found a one-liner which can uninstall all pip packages: pip3 freeze | grep -v "^-e" | xargs sudo pip3 uninstall -y I used to do the following: pip3 freeze > reqs.txt sudo pip3 uninstall -r reqs.txt I didn’t realise I could do pip uninstall -r reqs.txt -y and get rid of those confirmation questions. And I’m pretty sure I messed up the actual requirements file at least once when adopting this approach.

Continue reading "pip uninstall All"

Some Git

I did not realise my pull request was between branches of the same repository. Not sure if my friend realised. I moved the feature branch’s latest updates to my fork’s feature branch. I then made another pull request. I used the following commands to straighten things out: # Create a local branch with the same name as the origin remote feature branch git checkout -b feat/simple-compound-interest-calculators # Pull in the changes from the origin remote git pull # Set the upstream to the origin remote feature branch git branch --set-upstream-to=origin/feat/simple-compound-interest-calculators feat/simple-compound-interest-calculators # Check the remotes and their URLs git remote -v # Add the remote for my fork git remote add jiayee [email protected]

Continue reading "Some Git"