Local development is a joke (sometimes)

Local development has many benefits. When you can edit something on your local development machine and see the changes immediately (hot-reload), it makes the feedback loop smaller and makes development that much faster. Different toolkits have different ways of trying to solve local dev. Serverless Offline is a plugin for the Serverless Framework simulates AWS Lambda and other serverless providers to give a working offline version of that serverless app you are trying to create. So instead of calling e.g. https://12312321.execute-api.eu-north-1.amazonaws.com/dev you would call http://localhost:3000/. There is LocalStack which will emulate the whole AWS ecosystem. And most front-end frameworks have some sort of hot-reload enabled toolkit. ...

October 15, 2021 · 3 min · Kevin Kivi

Passwords in Email

It happened again. I created an account to a service (a domain registrar) and their welcome email contained the password I just gave them. You might think that that is fine, because maybe they didn’t store that password plain text in their DB. Maybe they hashed it. If you are confused about what hashing means, then read this auth0 article. Hashing in short: Normally passwords are stored in the database in a cryptographically secure manner, called a hash. This hash cannot be reversed to the password. Unless bruteforced, the stronger the password, the longer it will take, potentially up to tens/hundreds of thousands years (hashing algorithm and salting also can affect the difficulty in bruteforcing). This means that if somebody hacks the database, the attacker wont get all the customers’ passwords. ...

August 17, 2021 · Updated: August 18, 2021 · 3 min · Kevin Kivi

Add GSI to existing DynamodDB table (nodejs, aws-sdk)

If you are using the Serverless Framework, you can create DynamodDB and add one GSI (Global Secondary Index) with cloudformation syntax. How to add table: https://www.serverless.com/framework/docs/providers/aws/guide/resources/#configuration Here is the syntax to add GSI: https://cloudkatha.com/solved-cannot-perform-more-than-one-gsi-creation-or-deletion-in-a-single-update/ Official docs related to GSI cloudformation syntax: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-gsi.html That’s all fine until you need to add another GSI. You can’t do that with Cloudformation syntax [1]. Luckily we can do that programatically with Node.js (you could also use another programming language and just use the related aws-sdk library: https://aws.amazon.com/tools/ ...

August 5, 2021 · Updated: August 6, 2021 · 2 min · Kevin Kivi

Say goodbye to grep

ack is a famous code search tool to replace grep (in a lot of use cases): https://beyondgrep.com/why-ack/ Now there is something even better. There is ag aka The Silver Searcher: ggreer/the_silver_searcher It is like ack, but faster. Why not just grep? Hella fast. Like really really fast. It is beautifully optimized C. It ignores files from .gitignore Instead of doing this with grep: grep -R --exclude-dir=node_modules 'foobar' /path/to/your/code You can just do (if you have node_modules in your .gitignore): ...

July 25, 2021 · Updated: August 5, 2021 · 1 min · Kevin Kivi

Autostart any GUI app in Manjaro

In this example I will autostart the GUI package manager of Manjaro. Create a file e.g. ~/.config/autostart/pamac-manager.desktop In that file put: [Desktop Entry] Terminal=false Name=pamac-manager Type=Application Exec=/usr/bin/pamac-manager Icon=pamac-manager Comment=Package Manager In the Exec line put the path to your executable file. The rest you can probably guess. Source: https://specifications.freedesktop.org/autostart-spec/autostart-spec-latest.html

April 30, 2021 · 1 min · Kevin Kivi

Linux & OSX: Get file encoding

Sometime you need to know what’s your file encoding? Is it UTF-8, ISO 8859-1, ASCII or Windows 1252? You can find this out by using the file Unix command. Linux: file -i <filename> Mac OSX: file -I <filename> Example usage: username@server ~$ file -i somefile.php somefile.php: text/x-php; charset=us-ascii username@server ~$ file -i myutf8file.txt myutf8file.txt: text/plain; charset=utf-8 username@server ~$ file -i username.tar.bz2 username.tar.bz2: application/x-bzip2; charset=binary username@server ~$ If you want only the encoding. You can do file -i filename.txt | sed "s/.*charset=\(.*\)/\1/" E.g. ...

September 28, 2018 · Updated: April 9, 2021 · 1 min · Kevin Kivi

GIT: Get remote repository URL

So you need the remote repository URL. Maybe because you are trying to git add remote. You can type the below text to get the full info (needs to be done inside the folder you are working in): git remote show origin OR git config --get remote.origin.url After you know this, if you want you can create a new remote branch git add remote <name you want for your new branch> <URL you just got> git add remote newbranch git@hostedgit.yourdomain.com:name/project.git

September 27, 2018 · Updated: April 9, 2021 · 1 min · Kevin Kivi

PHP: Curl vs file_get_contents benchmark

I benchmarked curl vs file_get_contents in getting headers only and returning the HTTP Status Code. Here are the results: kevinkivi@server:~/my/secret/directory$ php curlvsfgctest.php Testing curl speed Domain: http://google.com Status: 301 Domain: http://yahoo.com Status: 301 Domain: http://nytimes.com Status: 301 Domain: http://theguardian.com Status: 301 Domain: http://wikipedia.org Status: 301 Curl speed was 0.35739207267761 Testing file\_get\_contents speed Domain: http://google.com Status: HTTP/1.0 301 Moved Permanently Domain: http://yahoo.com Status: HTTP/1.0 301 Moved Permanently Domain: http://nytimes.com Status: HTTP/1.1 301 Moved Permanently Domain: http://theguardian.com Status: HTTP/1.1 301 Domain: http://wikipedia.org Status: HTTP/1.1 301 TLS Redirect file\_get\_contents was 1.7153549194336 Below is the source code: ...

August 13, 2018 · Updated: April 9, 2021 · 2 min · Kevin Kivi

Javascript: Cronometer ratio changer

I created a script (with the help of my wife) which can change the ratio of foods. E.g.To make new food in Cronometer such as date paste, export “Dates” JSON from Cronometer. Then import the file. If the date paste is 15% water and 85% dates, then make the multiplier 0.85 and name it as you want. View at JSFiddle: https://jsfiddle.net/nake89/2k78jxpt/

July 21, 2018 · Updated: April 9, 2021 · 1 min · Kevin Kivi

cPanel: Listing all domains

I made a bash script listing all main domains and addon domains (for certain user by username or domain or for all users) in cPanel. Usage: lsdom [OPTION] [INPUT] Example: lsdom [cPanel username] Lists domains for certain user by username or domain or for all users Options: -d [domain] Displays all domains of the user of the input domain. -a, --all Lists all domains. -v, --version Displays version. -h, --help This help page. GitHub: https://github.com/nake89/lsdom

February 11, 2018 · Updated: April 9, 2021 · 1 min · Kevin Kivi