Latest Posts (20 found)
Nelson Figueroa 1 months ago

How to Actually Copy a List in Python

tl;dr: use the method. Say we have two Python lists – and . If we try to make a copy of and assign it to using the assignment operator , what really happens is that both and point to the same memory address. That means that any list-manipulating actions that are done on either or will affect the same list in memory. We don’t have actually have two separate lists we can act upon. In the example below, although we append the integer to , we can see that printing out shows the newly added element. That’s because both list variables point to the same memory address: Output of the program above: To make an actual copy, use the method. Then, when is modified, it is independent of , because is stored in a separate memory address. Now if we append the same integer to , will be completely unaffected. Output of the program above: Here’s more proof. We can print out the memory address of each variable to see when they’re the same and when they differ. We can do this using the function. Here are the same lists from above but this time with their unique identifiers printed out. In this case, the IDs match because both and point to the same memory address. The program above outputs: The memory addresses are the same. Now let’s try the same thing but using the method instead of just an assignment operation with : The program above outputs: We can see the memory addresses are different (most obvious due to the ending digits). Although I’ve been in the field for some time, I still have my smooth brain moments. This is a reminder to myself (and whoever reads this) to remember the basics! https://www.geeksforgeeks.org/python/python-list-copy-method/ https://www.geeksforgeeks.org/python/id-function-python/

0 views
Nelson Figueroa 1 months ago

Creating High Quality GIFs from Asciinema Recordings

Say you have a recording created with Asciinema named and now you want to convert that into a GIF. You can use the command (which is a separate installation ) to convert it like so: However, if you run with the default settings the resulting GIF won’t be high quality and it’ll look a little fuzzy. To get a high quality GIF you need to specify a big font size with the option: Here are two GIFs you can compare. The top one was created with the default settings. The bottom one was created with . Depending on your display, you may need to zoom in a bit to see the difference: It’s a noticeable difference. The trade-off here is that the higher quality GIF will be a bigger filesize, so be mindful of that. Try experimenting with different font sizes. I was expecting there to be some sort of or option, but you just need to increase the font to get higher quality GIFs with . https://docs.asciinema.org/manual/agg/ https://docs.asciinema.org/manual/agg/installation/ https://docs.asciinema.org/manual/agg/usage/

0 views
Nelson Figueroa 2 months ago

Quick Tip: Mute the Terminal Login Message with A .hushlogin File

Today I learned that you can create an empty file in your home directory on macOS and Linux to hide the login message you get when starting up a new terminal window or tab. I tried this on macOS but it should work on Linux too. For example, when I start up a new terminal window/tab I see the following message: After I create the file in my home directory, the login message goes away. First I created the file: Then I opened a new terminal window to verify that the message no longer shows up: https://stackoverflow.com/questions/15769615/remove-last-login-message-for-new-tabs-in-terminal https://www.cyberciti.biz/howto/turn-off-the-login-banner-in-linux-unix-with-hushlogin-file/

0 views
Nelson Figueroa 2 months ago

How to Use an AWS S3 Bucket as a Pulumi State Backend

I’ll be starting from scratch and creating an IAM user with access to an S3 bucket that will be used to store the Pulumi state file. If you’re working in an enterprise setting, your authentication methods may vary. The TL;DR is that you can run this if you already have an S3 bucket and AWS credentials configured on your machine: This post assumes you have the Pulumi CLI installed. Check out the following guide if you don’t have it installed: Download & install Pulumi . First, we need to create the S3 bucket where the Pulumi state file will be stored. I created a bucket called and left all the default settings as-is. Then we need to create an IAM user in AWS that the Pulumi CLI can use. This IAM user needs permissions to access the S3 bucket we just created. I go to IAM and create a new user. I just called it : Then in the next step, I selected “Attach policies directly” and selected the AWS-managed “AdministratorAccess” policy just to keep things simple. You can provide more fine-grained access depending on your needs. Then click “Next” at the bottom. In the next screen, double check everything and then click on “Create user”. Now that we have a user with the appropriate permissions, we’ll need to get an AWS access key and secret to use with the Pulumi CLI. Go to your IAM user and click on “Create access key” on the right side. In the next screen, select “Command Line Interface (CLI)”. Check the box at the bottom, then click “Next”. The next screen will ask for setting a description tag. This is optional. I chose to skip it and clicked on “Create access key”. We finally have our Access key and Secret access key. Save these somewhere safe and click “Done”. (Don’t worry, the credentials in the screenshot are fake.) Now we can try using these credentials to tell the Pulumi CLI to use the S3 bucket as a backend. Note that you do NOT need the AWS CLI installed. Pulumi just needs the AWS credentials. Create the file if you don’t have it. Then add in your credentials there under the profile. (You can add more profiles, but this is beyond the scope of this post.) You’ll need the bucket’s region and your local AWS profile name to use S3 as a backend. The command formula looks like this: In my case, the command looks like this (make sure to edit for your needs): A successful login shows the following message: Alternatively, you can add your backend to your file. This is useful if you’re working on multiple Pulumi projects that each have different backends. You won’t need to run all the time. Just add a key and a nested key: More information here: Pulumi project file reference . Finally, it’s time to test this out. To demonstrate, I created a simple Pulumi program by running: You can choose whatever language you want though. This is the main Pulumi code that is generated. It’s code for creating an S3 bucket: Then I ran and it worked! And just to double check, I can see that my previously empty S3 bucket now has contents created by the Pulumi CLI: https://www.pulumi.com/docs/iac/download-install/ https://www.pulumi.com/registry/packages/aws/installation-configuration/ https://www.pulumi.com/docs/iac/concepts/state-and-backends/#aws-s3 https://www.pulumi.com/docs/iac/concepts/projects/project-file/ https://ashoksubburaj.medium.com/pulumi-with-aws-s3-as-backend-ac79533820f1

0 views
Nelson Figueroa 3 months ago

Local Text Summarization With Ollama and Python Is Just String Manipulation

I’ve used LLMs before but through an interface (i.e. ChatGPT , Gemini , etc) but when I was trying to run a LLM locally I was overthinking how it worked. Basically, it comes down to this: You pass in a string, and you get a string in return. That’s it. So if we want to run a LLM locally using Python to summarize files, we build strings with Python and pass them into Ollama. If you want to read in files, open them in Python and concatenate the text with your prompt string. Then pass in the prompt string to Ollama. Python is just a bridge between you and Ollama. I’ve included some basic examples. The examples assume you have Ollama installed locally. This is straightforward. Open a file and concatenate the text with a prompt which gets passed into Ollama: If you want to pass in multiple files in one prompt, you have to read and concatenate the files into a string, which you then concatenate into the prompt itself. If you want to read in multiple files but the files are huge, you may exceed the context limits of your model. You can still concatenate files/strings where possible but you can circumvent this by creating several chats. You’re basically running the code more than once, which means you can use a loop. The code above gives us separate summaries. But what if we want a single summary of all the files involved and they each exceed context limits? We can create a summary of each file, then create a summary of the summaries! It’s all string concatenation when you really think about it. That should be enough to get started. Thinking about all of this as just string manipulation made it “click” for me. https://ollama.com/download/ https://ollama.com/library/gpt-oss https://github.com/ollama/ollama-python/tree/main/examples

0 views
Nelson Figueroa 3 months ago

Proper Hugo Template Syntax Highlighting with go-html-template

I recently learned that you can highlight Hugo template code blocks by specifying after the opening backticks. So the opening backticks in a Markdown file look like this: It makes a huge difference when highlighting Hugo template code blocks. I was previously using for syntax highlighting and it wasn’t as good. For example, here is some HTML + Hugo templating stuff being highlighted with : Here’s the same code block but with specified: Big difference! Note that I’m using Chroma for syntax highlighting so your experience may vary, but Chroma comes by default with Hugo. https://gohugo.io/content-management/syntax-highlighting/ https://github.com/alecthomas/chroma

0 views
Nelson Figueroa 4 months ago

A Trick To Remove Unwanted Whitespace After Links in Hugo

TL;DR: You can use the shortcode to remove trailing whitespace on links in Hugo. For some reason, Hugo was rendering links with a space after them. Here’s a screenshot of what that looked like: It’s subtle but becomes more obvious and distracting in link-heavy pages. Here is the markdown that I was using to generate the link above. Nothing out of the ordinary: In Hugo, you can apply post-processing to links through link render hooks by editing the file. Here’s my terrible template that I use to process links. Once again, nothing stood out that would add unnecessary whitespace after links: Here is the HTML that was generated by Hugo based on the Markdown I wrote and the processing in . This is straight from the browser dev tools: The period was on its own line, which looks suspicious. Why is there additional space being added though? I tried modifying my CSS, my Markdown, and to see if I could remove the whitespace but nothing worked. Eventually, I was out of ideas and asked ChatGPT what could be going wrong. ChatGPT suggested I could add the shortcode to to remove the whitespace. Apparently that would force the removal of both leading and trailing whitespace. And sure enough it worked! I modified my template to include the shortcode at the end of the tag in the hightlighted line: Then my links were rendering without additional space after them, and here’s a screenshot showing that: The weird thing is that when I checked the HTML being generated, it looked identical to the original before I added the shortcode and I had no idea why: But at least the whitespace was gone when viewing the article in a browser. That’s what matters. This shortcode trick can probably be applied to other areas of Hugo and not just for links, but I haven’t done any additional experimenting. Wherever ChatGPT stole got this information from. I feel weird using ChatGPT as a reference but that really is how I discovered the solution.

0 views
Nelson Figueroa 5 months ago

Remove Unnecessary Hugo Meta Tag to Keep HTML Lean

I like to keep my Hugo site as lean as possible for performance reasons and to save on hosting costs. I recently discovered that Hugo generates a HTML tag with the Hugo version in the tag. This is done by default and looks like this: To remove this tag, we can disable it in or by setting the boolean to . If setting doesn’t work, do a global search in your Hugo project for . This shortcode outputs the same tag and doesn’t respect the configuration (at least as of Hugo v0.147.8). https://gohugo.io/configuration/all/#disablehugogeneratorinject https://gohugo.io/functions/hugo/generator/

0 views
Nelson Figueroa 6 months ago

Validate HTTP Status Codes in Go Using Built-in Constants

Go has useful constants in the net/http package that can make your code more readable when checking for status codes in responses. For example, instead of writing something like You can write Unfortunately the the link doesn’t show any any full, working examples. So here’s an example covering some of the more common http status codes that you can use and modify as needed. There’s also a function that allows you to pass in status codes and get a message for logging purposes or displaying to users. You can see all the responses in the source code here , it’s a bunch of statements. For example, lets say we want to display a message if we don’t get a 200 status code. Instead of writing code to print out a different message depending on the status code value, we can use the function: Super convenient. https://pkg.go.dev/net/http https://go.dev/src/net/http/status.go

0 views
Nelson Figueroa 6 months ago

It’s 2025, Why Aren’t You Using an Ad Blocker?

I find myself asking this any time I discover that someone uses a web browser with no ad blocking solution. More specifically, it blows my mind when tech-savvy people that work in software development (and related roles) don’t use ad blockers. I don’t understand why. The “main” web is a terrible experience when browsing without ad blockers. If you’re one of those people that doesn’t have an ad blocker here are some links to improve your web browsing experience. The best and arguably only ad blocker you’ll need for your browser is uBlock Origin . It has worked consistently for me on Firefox and Chrome for many, many years. Here are some convenient links to get uBlock Origin: Safari doesn’t support extensions like other browsers. While there is some tracking protection out of the box it doesn’t compare to uBlock Origin. If you REALLY want to keep using Safari then check out AdGuard for Mac . It blocks ads system-wide on macOS and not just in Safari. If you like the Safari aesthetic but don’t want to install AdGuard, check out Orion Browser . It comes with ad blocking out of the box. It’s based on WebKit just like Safari. There’s even an iOS app available. Brave Browser is also a great browser if you want an ad-free web experience. It’s available on all major platforms (Windows, Android, Linux, macOS, iOS) and it comes with ad blocking built in. I hesitate a bit to recommend Brave because it comes with some optional crypto bullshit called Basic Attention Token , but you don’t have to opt into that. There are many options for blocking ads regardless of the device you’re using. Start browsing the web with an ad blocker and you’ll never go back to browsing the normal ad-infested web. Get the uBlock Origin Firefox extension Get the uBlock Origin Chrome extension Get the uBlock Origin Microsoft Edge extension (if you use Edge for some reason) Get Orion for macOS Get Orion for iOS Get Brave Browser

0 views
Nelson Figueroa 9 months ago

How to Clone a Specific Git Branch Without Other Branches

To clone a specific branch of a git repository without cloning all other branches, use the following command formula: For example, if you want to clone the branch of the Kubernetes GitHub repository , run: If you only want to clone the latest commit of a specific branch (which results in a faster and smaller cloning operation) use . The command formula looks like this: And here is another example using the branch of the Kubernetes GitHub repository : https://www.freecodecamp.org/news/git-clone-branch-how-to-clone-a-specific-branch/ https://git-scm.com/docs/git-clone

0 views
Nelson Figueroa 9 months ago

Delete All Pulumi Stacks with One Command

There currently isn’t a way to delete all stacks with so this is an alternative way to achieve that. To delete all Pulumi stacks in the current Pulumi project you can run the following command: Be careful when doing this. To delete all Pulumi stacks across all Pulumi projects we need to use instead of . So the full command is: List pulumi stacks (use option for all stacks across all projects): Start at the second line of the previous output: Delete all occurrences of . There is a character next to the currently selected stack and we need to remove this: Print only the first column: This is a loop in one-liner format. It reads the previous output line by line and assigns each line to an array called , then runs the command on each stack. https://stackoverflow.com/questions/7318497/omitting-the-first-line-from-any-linux-command-output https://www.pulumi.com/docs/iac/cli/commands/pulumi_stack_ls/ https://www.pulumi.com/docs/iac/cli/commands/pulumi_stack_rm/

0 views
Nelson Figueroa 10 months ago

How to Disable CSS Animations and Transitions

To disable CSS animations and transitions you can try adding the following to your CSS: If that doesn’t work, try using in your CSS: You can also put these into a CSS class and apply to HTML elements as needed if you still want animations in some places: If you’re using a CSS library that comes with animations by default it may be a pain to maintain a modified version of it without animations. It’s easier to write your own CSS to disable animations and transitions. My motivation behind this post was disabling button animations when using daisyUI on a side project. Note that I am not a CSS expert and there may be other ways of animating elements via CSS that I did not cover here. Also, this doesn’t help if elements are being moved around by JavaScript. But you can easily disable JavaScript for any site through your browser :) https://stackoverflow.com/questions/11131875/what-is-the-cleanest-way-to-disable-css-transition-effects-temporarily https://stackoverflow.com/questions/31576156/what-does-animationnone-do-exactly https://developer.mozilla.org/en-US/docs/Web/CSS/animation https://developer.mozilla.org/en-US/docs/Web/CSS/transition

0 views
Nelson Figueroa 10 months ago

We Exist Only to Work

I randomly checked LinkedIn the other day and I saw this banner at the top of my feed: It’s obviously an advertisement but it made me think about how much we actually work in our lives. I looked up the average lifespan of a male in the USA and got this: That’s depressing. We work most of our lives. I know that wasn’t their intent but yeah. https://www.cdc.gov/nchs/fastats/life-expectancy.htm

0 views
Nelson Figueroa 10 months ago

There Is Little Incentive to Participate in Your Employer's Hackathons

I don’t understand why software developers participate in voluntary company hackathons on top of their day-to-day work. The company benefits the most out of whatever software is developed during these hackathons. In general, most of the work you do in your company mainly benefits the company, but I think this is especially true for hackathons. I’d rather do a hackathon outside of work with friends or colleagues, even if there is no financial gain. You might ask, “if you don’t care about money, why not just do a hackathon for your company?”. If I join a hackathon outside of work I can do it to potentially create a side hustle or simply for the joy of creating software. If I volunteer to work on a hackathon for my employer, my ideas and creations are taken from me even if I enjoy working on these projects. It feels like someone is taking advantage of me, specially if hackathons are not part of my job description and I receive no additional compensation for participating. If there is compensation, it’s usually something like a $100 Amazon gift card. Maybe it’s just me that can’t get motivated or excited about a company hackathon. I can summarize company hackathons like this: you come up with a million dollar idea for your employer and (maybe) get $100 in return.

0 views
Nelson Figueroa 11 months ago

Fix "Efficient Cache Policy" Warning on PageSpeed Insights When Using Amazon CloudFront

I ran into this warning recently on PageSpeed Insights : “Serve static assets with an efficient cache policy” . The warning highlighted three assets that had no “Cache TTL” defined: To resolve this warning, I added a header with the value to the HTTP responses of my domain ( is the number of seconds in a year). I host nelson.cloud on Amazon CloudFront . I added this header to the CloudFront Distribution that the domain points to. This can be done by adding a “Response headers policy” in the Behavior of the Distribution. I wrote post demonstrating how to do this in detail: How to Add a Custom Response Header to an Amazon Cloudfront Distribution . After the header was configured, I checked PageSpeed Insights again and the warning had gone away for the assets under my domain : (The remaining asset is not under my control so I can’t fix that one.) Note that you may be able to use a different value smaller than for your header. I chose a year in seconds to be on the safe side for PageSpeed Insights. https://developer.chrome.com/docs/lighthouse/performance/uses-long-cache-ttl/ https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html

0 views
Nelson Figueroa 11 months ago

How to Add a Custom Response Header to an Amazon Cloudfront Distribution

This post assumes you already have an Amazon CloudFront Distribution deployed and properly configured. You’ll also need knowledge about HTTP headers if you found your way here because your boss told you to do this and “figure it out”. Go to the AWS Console and click into your CloudFront Distribution. Then click on the “Behaviors” tab. If you already have a behavior, you can edit the existing one. Otherwise, create a behavior. I won’t cover the other Behavior settings as that is out of the scope of this post, but to add a custom response header look for the “Response headers policy - optional ” field which is under “Cache key and origin requests”. Click on the “Create response headers policy” link. On the next page fill in the “Name” field at the very top. Then, scroll a bit down and you should see the “Custom headers - optional ” field. Click on the “Add header” button and add the custom header you’d like. In my case, I added the header with a value of . I also checked the box because I want this header to take precedence over other headers that may be set in the origin. Then click the “Create” button on the bottom right. You’ll be redirected to CloudFront > Policies. You can see your newly created response header under the “Response headers” tab. In my case it’s called . Now that this custom header policy is created, browse back to your Distribution and click on the “Behaviors” tab. Edit an existing Behavior or create one. Scroll down to the “Response headers policy - optional ” field again. Then, select your new response header policy. Then save your changes. Wait a few minutes and your distribution will be updated with the new header. There is no need to create an Invalidation . You can test this out by running . Your output should look something like this. Look for your custom header in the output. In my case, shows up at the very bottom. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers https://stackoverflow.com/questions/56187791/how-to-set-cache-control-header-in-amazon-cloudfront https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/modifying-response-headers.html

0 views
Nelson Figueroa 11 months ago

How to Generate the Current Date and Time in Hugo

Here are a bunch of Hugo snippets you can use to generate the current date and time in your Hugo site. You can copy and paste these into HMTL templates. If you want to use these within your posts/articles (Markdown files) you’ll need to create a shortcode first. Scroll down to the Using Shortcodes section for more details. I’m running Hugo v0.140.0+extended. For all examples, I will assume the time is 2024-12-22 2:30PM PT. You can Specify AM or PM as well: Essentially just changing to . It’s possible to add just about anything in place of the timezone and it’ll take it. You can even add text that isn’t a valid timezone. There are two ways that I found of doing this. The first way: Output. Note how Hugo changed the offset from to in this case: The second way: Output. Hugo once again changed the offset from to : These snippets work for your current timezone but if you use a CI/CD solution you may need to specify the timezone through an environment variable or etc. It depends on your CI/CD solution. I couldn’t find a way to set the timezone in Hugo itself so I don’t think it’s possible. These snippets can be copied and pasted into templates. However, to use them in Markdown files, you’ll need to create a separate file in and then use that shortcode in a markdown file. For example, I can create a file in with the following contents: Then I can reference this shortcode in a markdown file with this syntax: An example along with some other markdown: https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/7 https://community.cloudflare.com/t/hugo-timezone-format-issue/390678

0 views
Nelson Figueroa 1 years ago

Render HTML and CSS if JavaScript Is Disabled Using the `<noscript>` Tag

I recently learned about the HTML tag . HTML and CSS contained within tags will be rendered if JavaScript is disabled in the browser. For example, try reloading this page with JavaScript disabled and you’ll see a new message below: The HTML for the message above looks like this: Here’s an example where CSS styles within tags are applied when JavaScript is disabled. Try reloading this page without JavaScript and the message below will be italicized. And this is what the HTML and CSS looks like for the example above: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript

0 views
Nelson Figueroa 1 years ago

The prefers-reduced-motion CSS Media Query

I recently learned about the CSS media query . In a nutshell, if a user enables reduced motion on their device/browser, the CSS styles within this media query will be applied. For example, if buttons have animations when they’re clicked like this: We can disable those animations if a user has enabled reduced motion on their device by using the media query like this: Technically, the CSS being applied under doesn’t need to be related to motions or animations. It’s possible to do other things, like changing the background color, if a user prefers reduced motion. So something like this is possible too: The Mozilla docs cover how to enable reduced motion on several browsers: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion https://developer.mozilla.org/en-US/docs/Web/CSS/@media https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries

0 views