Skip to main content
  1. Tags/

Coding

LLMs and an old dev

·1 min
A lot of developers seem to be afraid of generative AI and LLMs because it may replace their jobs. But as an older developer who sometimes has a hard time keeping up with new frameworks and technologies, LLMs have been life-saving. Not only is my productivity high, but I am also able to keep up with new languages and codebases and be productive almost immediately. I used to think about moving to management because it seemed I could not keep up with tech, but now I have new confidence that I can keep doing my hobby as a profession for another few years.

Backup VPS

·1 min
Here are simple steps to backup your VPS. Backup MySQL database # Create a directory to store the backup files. Then run mysqldump command to backup your database. mysqldump -u your_mysql_user -pyour_mysql_password your_database_name > /path/to/dump_$(date +\%Y\%m\%d\%H\%M\%S).sql Or you run it as superuser and backup all databases at once. sudo mysqldump --all-databases > /path/to/dump_$(date +\%Y\%m\%d\%H\%M\%S).sql To automate this, schedule a cron job that will run this command on a daily basis.

A quick script to build and deploy hugo site on VPS

·2 mins
I had been using GitHub and Netlify for this site but lack of some features such as access to server logs finally got too much. So I decided to move this blog to my VPS. One thing I really love about using Github is CI/CD and Github Actions. But I wanted something even simpler with less dependencies. So I decided to use a simple bash script to build and deploy the site.

undefined method xxxxx' for #< Hash:0x00000 >

·1 min
This error in our Rails application drove me crazy. The error was like this: undefined method xxxxxx' for #<Hash:0x000000001234> The problem was that I was calling a method like this: a_method(var: var) And the method definition was like def a_method(var: var) which resulted in something called variable shadowing and caused clash between variable passed in the method and local variable being defined. The fix was to change method definition to def a_method(var:)

Script inherits from native type 'RigidBody2D', so it can't be assigned to an object of type: 'Node2D'

·1 min
Getting this error while following this tutorial in Godot v4.0.1. In my case, I had added Node2D. The fix was to right-click on the problem node under Scene and click Make Scene Root. And then delete Node2D. Here is what diff looked like: diff --git a/2d-game-tutorial/Mob.tscn b/2d-game-tutorial/Mob.tscn index 9eb1630..e720d7f 100644 --- a/2d-game-tutorial/Mob.tscn +++ b/2d-game-tutorial/Mob.tscn @@ -48,20 +48,18 @@ animations = { radius = 36.0 height = 100.0 -node name="Mob" type="Node2D"] -script = ExtResource("1_73gb4") - -node name="RigidBody2D" type="RigidBody2D" parent="."] +node name="RigidBody2D" type="RigidBody2D"] collision_mask = 0 gravity_scale = 2.66454e-15 +script = ExtResource("1_73gb4") -node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="RigidBody2D"] +node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] scale = Vector2(0.75, 0.75) sprite_frames = SubResource("SpriteFrames_c1yjy") animation = &"walk" -node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] +node name="CollisionShape2D" type="CollisionShape2D" parent="."] rotation = 1.5708 shape = SubResource("CapsuleShape2D_h1pjc") -node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="RigidBody2D"] +node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]

How much can you really get out of a 4$ VPS?

·1 min
I am a big fan of cheap VPSs. I start many personal projects, bring up a VPS, play around and then wipe it. Never have to worry about accidentally running up a bill in 100s or 1000s of dollars. I run this blog on a $4 server. So this was interesting to read how far can a cheap VPS go.

How to backup Kubernetes' Config

·1 min
The easiest solution seems to be the following script by Stack Overflow user, Timothy Perez : <pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">#!/bin/bash # NAMESPACED EXPORTS for ns in $( kubectl get ns --no-headers | cut -d " " -f1 ) ; do kubectl --namespace = " ${ ns} " get -o = json bindings,cm,ep,ev,limits,pvc,po,podtemplates,rc,quota,secrets,sa,svc,controllerrevisions,ds,deploy,rs,sts,localsubjectaccessreviews,hpa,cj,jobs,leases,ev,ds,deploy,ing,netpol,rs,pods,netpol,pdb,roles,rolebindings | \ jq '.items[] | select(.type!="kubernetes.io/service-account-token") | del( .spec.clusterIP, .metadata.uid, .metadata.selfLink, .metadata.resourceVersion, .metadata.creationTimestamp, .metadata.generation, .status, .spec.template.spec.securityContext, .spec.template.spec.dnsPolicy, .spec.template.spec.terminationGracePeriodSeconds, .spec.template.spec.restartPolicy )' >> "./ ${ ns} .json" done # NON-NAMESPACED EXPORTS kubectl get -o = json cs,ns,no,pv,mutatingwebhookconfigurations,validatingwebhookconfigurations,crds,apiservices,tokenreviews,selfsubjectaccessreviews,selfsubjectrulesreviews,subjectaccessreviews,csr,psp,nodes,psp,clusterrolebindings,clusterroles,pc,sc,volumeattachments | \ jq '.items[] | select(.type!="kubernetes.io/service-account-token") | del( .spec.clusterIP, .metadata.uid, .metadata.selfLink, .metadata.resourceVersion, .metadata.creationTimestamp, .metadata.generation, .status, .spec.template.spec.securityContext, .spec.template.spec.dnsPolicy, .spec.template.spec.terminationGracePeriodSeconds, .spec.template.spec.restartPolicy )' >> "./cluster_non-namespaced_export.json" Script copied here under CC BY-SA 4.0 license

Kubernetes not passing full path to Nodejs

·1 min
I spent hours troubleshooting why the url path was getting stripped from requests in our Nodejs/Expressjs based app. The reason was this line in Kubernetes’ Ingress: nginx.ingress.kubernetes.io/rewrite-target : / Removing it fixed the issue. Check the Kubernetes documentation for more details.

Ask HN: Software Engineer hitting 40: what's next?

·1 min
Recent thread on Hacker News, https://news.ycombinator.com/item?id=29360119, was very interesting for me especially since I turned 40 this year. Programming is something I enjoy and am pretty good at it. I’m still not at the top of the salary range for programmers but this is a tough question. I can get into FAANG but there is still a ceiling of how much one can earn as a software engineer. This comment says it best:

Wealth Lab Pro Earning Play Screener

·1 min
This is a quick script that I use to find options to buy or sell. using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components; namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { DataSeries maFast = EMAModern.Series(Close, 50 ); DataSeries maSlow = EMAModern.Series(Close, 200 ); DataSeries maFast_1 = EMAModern.Series(Close, 10 ); DataSeries maSlow_2 = EMAModern.Series(Close, 50 ); DataSeries ma = EMAModern.Series(Close, 10 ); DataSeries maFast_3 = EMAModern.Series(Close, 10 ); DataSeries maSlow_4 = EMAModern.Series(Close, 50 ); PlotSeries(PricePane,EMAModern.Series(Close, 50 ),Color.Red,LineStyle.Solid, 2 ); PlotSeries(PricePane,EMAModern.Series(Close, 200 ),Color.Green,LineStyle.Solid, 2 ); PlotSeries(PricePane,EMAModern.Series(Close, 10 ),Color.Blue,LineStyle.Solid, 2 ); PlotSeries(PricePane,EMAModern.Series(Close, 50 ),Color.Red,LineStyle.Solid, 2 ); PlotSeries(PricePane,EMAModern.Series(Close, 10 ),Color.Blue,LineStyle.Solid, 2 ); //for(int bar = GetTradingLoopStartBar(201); bar < Bars.Count; bar++) int bar = Bars.Count - 1 ; { if (IsLastPositionActive) { Position p = LastPosition; if (p.EntrySignal.Contains("Group1|" )) { if (CrossUnder(bar, maFast_3, maSlow_4)) { SellAtMarket(bar + 1 , p, "Group1" ); } } } else { if (maFast[bar] > maSlow[bar]) { if (maFast_1[bar] > maSlow_2[bar]) { if (Close[bar] < ma[bar]) { if (EarningsDate.InWindow( this , bar, "earnings per share" , 7 , 0 )) { BuyAtMarket(bar + 1 , "Group1|" ); } } } } } } } } }

Oculus Quest 2 Review

·3 mins
I was debating between PS5 and Quest 2 (Affiliate link), and yes it is like comparing apples and oranges, but in the end Quest 2 won. I will likely buy PS5 at some point though. But before I buy PS5, I need a new TV with 4K and HDR. It seems pointless to play PS5 on 1080p TV from early 2010s. Quest 2 is not my first experience with Virtual Reality. I tried PSVR about 2-3 years ago but the mess of wires really turned me off with the idea of VR. When I found out that Quest 2 is completely wireless, I got interested in it again. I was not very excited about needing Facebook account to use it though.

Docker in 5 minutes

·2 mins
I have been using Docker and Kubernetes for several years now but never really took any time to really read about it. There were a lot of gaps in my understanding of how Docker works and what really is possible with it. Just recently my employer started to offer a Udemy subscription, so I took the Hands on Docker course. Here are some of the important things I learned in this course.

Json_error_ctrl_char

·1 min
I was using mcrypt to encrypt json_encoded data. On the other side, mcrypt was able to decrypt data but json_decode was not working. It would throw JSON\_ERROR\_CTRL_CHAR error. However, without mcrypt, json_decode worked flawlessly. After some trial and error, I found that applying trim function after decrypting data would let me use json_decode without any issues.

Error Xcode Select Error Tool Xcodebuild Requires Xcode Active Developer Directory Command Line Tools Instance

·1 min
Playing with Cordova, I was getting this error when building iOS version: Error: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory is a command line tools instance Even full install of Xcode didn’t fix this error. The solution was to run the following command to use full Xcode instead of command line tools version that I had installed earlier: sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer

Setup Outgoing Email on Lightsail Ubuntu VPS

·1 min
I followed instructions here: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-18-04 Everything seemed okay but emails were not getting delivered. Logs showed me that smtp connections were timing out: tail -f /var/log/mail.log May 3 12:28:10 postfix/smtp[3160]: connect to gmail-smtp-in.l.google.com[172.217.197.27]:25: Connection timed out May 3 12:28:10 postfix/smtp[3160]: connect to alt1.gmail-smtp-in.l.google.com[2800:3f0:4003:c00::1a]:25: Network is unreachable May 3 12:28:40 postfix/smtp[3160]: 4984C41A1E: to=<xxxx@gmail.com>, relay=none, delay=3246, delays=3186/0.01/60/0, dsn=4.4.1, status=deferred (connect to alt2.gmail-smtp-in.l.google.com[2a00:1450:400b:c00::1a]:25: Network is unreachable) However, I could ping any of the above ip addresses just fine.

hsts Neterr_cert_common_name_invalid

·1 min
Without full understanding, I had enabled HSTS on amerkhalid.com with option includeSubDomains. I had a subdomain that was used as “Custom Domain” to SmugMug site. After enabling HSTS, these subdomains started to throw NET::ERR_CERT_COMMON_NAME_INVALID. The fix is of course simple, don’t use includeSubDomains. But that opens up your top level domain to man in the middle attacks. For now, I decided to follow the best practices and leave includeSubDomains enabled. And decided to not use a custom domain for my SmugMug site.

TypeError: require.extensions.hasOwnProperty is not a function

·1 min
While playing with https://github.com/alexa/interactive-adventure-game-tool, I ran into the following error: > interactive-adventure-game-tool@1.0.0 start /Users/amer/alexa/interactive-adventure-game-tool > node node_modules/gulp/bin/gulp.js /Users/amer/alexa/interactive-adventure-game-tool/node_modules/require-dir/index.js:97 if (!require.extensions.hasOwnProperty(ext)) { ^ TypeError: require.extensions.hasOwnProperty is not a function at requireDir (/Users/amer/alexa/interactive-adventure-game-tool/node_modules/require-dir/index.js:97:37) at Object.<anonymous> (/Users/amer/alexa/interactive-adventure-game-tool/gulpfile.js:1:85) at Module._compile (module.js:660:30) at Object.Module._extensions..js (module.js:671:10) at Module.load (module.js:573:32) at tryModuleLoad (module.js:513:12) at Function.Module._load (module.js:505:3) at Module.require (module.js:604:17) at require (internal/module.js:11:18) at Liftoff.handleArguments (/Users/amer/alexa/interactive-adventure-game-tool/node_modules/gulp/bin/gulp.js:116:3) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! interactive-adventure-game-tool@1.0.0 start: `node node_modules/gulp/bin/gulp.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the interactive-adventure-game-tool@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/amer/.npm/_logs/2018-01-02T05_12_24_832Z-debug.log The solution was to update require-dir to version 0.3.2 in package.json and run npm install again.

Troubleshooting Kubernetes Ingress

·1 min
Setting up Ingress is an easy process but when it doesn’t work it gets really painful. First, make sure you have Ingress Controller setup correctly. This is in addition to Ingress resource and should be automatically setup by your cloud provider. When I was trying to setup a Kubernetes cluster on IBM Cloud, I ran into a lot of issues. It seems due to my permissions level something went wrong during provisioning of Kubernetes and Ingress Controller was not setup correctly. I went through a lot of steps including recreating alb , ingress resources, etc. The final fix was to login to IBM Cloud as superuser to change Access Policies for the cluster. Once I did that, everything just worked magically.

WordPress to Hugo to WordPress to Hugo

·2 mins
I moved all my blogs back to Hugo. I have gone back and forth between Wordpress and Hugo several times. WordPress makes it really easy to write and publish content. On this domain, I was using WordPress as a bookmarking service. With PressThis plugin, I was able to use a bookmarklet and publish a new post from any page on the web. But that plugin has not been updated in a while and it seems with every new WordPress release something would break. A few times, I was able to hack it to keep going. But lately, I cannot keep up with it. I will have to figure out a better way to bookmark but for now, I didn’t want to deal with WordPress. And easy bookmarking was the only reason why I was using WordPress.

iPad Pro as main machine after 2 years

·2 mins
I got my iPad Pro at the end of 2017. Before buying it, I had read many blog posts by various developers who were using iPad for programming and web development. But soon after I bought it, I realized that serious web development on iPad is hard. The biggest issue was debugging JavaScript and CSS without web tools. At first, I was having buyer’s remorse but I loved the form factor of iPad and loved drawing on it. I am used to reading on Kindle and iPad was just too heavy for long reading sessions but it was a very decent reading device for quick reading sessions. So I kept it.