How to Encrypt Files on macOS

Tyler Tyler (285)
Total time: 5 minutes 
Updated: July 22nd, 2020

This guide shows how to encrypt a folder on macOS with password protection.

Posted in these interests:

macos
PRIMARY
40 guides
security
23 guides

You can create a folder directly in Finder. Navigate to the desired directory and create a folder. We will create an encrypted disk image from this folder. The files we want to secure will go inside of this folder.

Move any files that you wish to protect inside of the folder you just created.

You can find the Disk Utility app in Applications > Utilities or just hit cmd + space bar and search for “Disk Utility”.

Create a new Disk Image from this folderCreate a new Disk Image from this folder

Click on File > New Image > Image From Folder.

A Finder window will appear. Find and select the folder you want to encrypt, then click Choose.

Choose a name and location for the imageChoose a name and location for the image

Choose a name and location for the image.

Keep in mind, “.dmg” will be automatically appended to the name you choose.

Then select either either 128 or 256 bit encryption.

By default, this will create a read-only image. If you’ll need to write to this folder again in the future, change the Image Format to read/write.

Set the password for the imageSet the password for the image

Enter the password, verify, and click save.

This password will be required when you try to mount the disk image to view the contents so you should write down this password.

Use a strong password, and store it securely. Consider using a password manager like 1Password or Dashlane.

Test out the imageTest out the image

To test the image you’ve created, find the image in Finder and click to open. When prompted, enter the password you set previously. This will mount the image and display the contents of the folder.

When you’re finished, make sure to unmount the image. You’ll see the image in the left column of finder and you can click the eject icon to unmount.

We’re hiring!
Are you a passionate writer? We want to hear from you!

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Calling all writers!

We’re hiring. Write for Howchoo

Tyler's profile pictureTyler
Joined in 2015
Software Engineer and creator of howchoo.
Share this guide!
Related to this guide:
Git: Move Your Latest Commits to Another BranchGit: Move Your Latest Commits to Another Branch
Sometimes we start writing code without managing our branches in advance. Then we make commits in master (or some other base branch) when we intended to carve off a new feature branch.
Tyler's profile picture TylerView
In these interests: git
GitHub Package Registry: Manage Packages Alongside Your Source CodeGitHub Package Registry: Manage Packages Alongside Your Source Code
Publishing software packages is already pretty easy, so what does GitHub’s Package Registry offer that we don’t already have?
Tyler's profile picture TylerView
In these interests: newsgithubgit
Git: Handling Merge Conflicts Using "Ours" and "Theirs"Git: Handling Merge Conflicts Using "Ours" and "Theirs"
Nothing is certain, except death and taxes and merge conflicts. -Benjamin Franklin
Tyler's profile picture TylerView
In these interests: git
People also read:
Cleaning up unused tags is an important part of Git housekeeping. This guide will show you how to delete tags from both local and remote Git repositories.
Git is an open-source version control system (VCS). In order to use Git to track changes in your code from the command line, you’ll need to download, install and configure it on your computer.
I’ve wanted to start blogging again after a few years off. I was thrilled to find that I can blog using markdown in Vim and publish using git.
When you’re using git routinely, it’s helpful to know which branch you’re currently on without having to type git status or git branch.
This short guide will show you how to list all remote branches in Git.
There are some fundamental git commands that you will use frequently that are hard to work into a “how-to” guide. Here are some basic git commands and how to use them. These are in no specific order.
If you’re working on your development environment but you need access to a branch that someone else has pushed to “origin” then you’ll need to follow these steps.
Hub overview Hub is a command-line tool that wraps git and provides extra functionality that makes working with GitHub easier.
Create GitHub personal access tokens for the command line
This short guide shows you how to set up access to your SourceTree repos through Alfred.
Posted in these interests:
gitgit
git
PRIMARY
Discuss this guide:
We’re hiring!
Are you a passionate writer? We want to hear from you!
We’re hiring!
Are you a passionate writer? We want to hear from you!

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Total time: 20 minutes 
Updated: July 22nd, 2020
Calling all writers!

We’re hiring. Write for Howchoo

pi
PRIMARY
215 guides
python
67 guides
How to Enable SSH on Raspberry Pi Without a Screen How to Enable SSH on Raspberry Pi Without a ScreenThe SSH protocol is disabled by default.
How to Connect to a Raspberry Pi Remotely via SSH How to Connect to a Raspberry Pi Remotely via SSHThe preferred (and most common) method of connecting to your Pi to run commands.
Calling all writers!

We’re hiring. Write for Howchoo

Tyler's profile pictureTyler
Joined in 2015
Software Engineer and creator of howchoo.
For Raspberry Pi beginners who still love to follow along in a book.
Michael's profile picture MichaelView
In these interests: booksretropiepi
What’s better than an experiment? An experiment in space!
Michael's profile picture MichaelView
In these interests: kidspinews
In these interests: pi
Kali Linux is a great distribution for Raspberry Pi users who want to get to grips with security testing.
The Raspberry Pi micro-computer grows in power with each new model release, with more resources that make it a more capable, low-cost content server for your media and resources.
Laptops, smartphones, tablets, even lightbulbs—an endless number of devices now have the ability to connect to your local network and the wider internet.
The Raspberry Pi was designed to boot from an SD card, but in some cases, it’s convenient to boot from a USB drive.
Get the new official Raspberry Pi OS on your Pi.
New to the Raspberry Pi? Start here.
Blocking ads just got easier with Pi-hole, a network-wide ad blocker for the Raspberry Pi
Don’t skip out on a proper case for your Pi 4.
The only Raspberry Pi Bluetooth guide you’ll ever need.
Your favorite MS OS on the Pi.
pi
PRIMARY
The Raspberry Pi is a small, inexpensive computer developed by the Raspberry Pi Foundation in the United Kingdom.
Python is howchoo’s favorite programming language. We believe python promotes the most organized and performant codebase possible. We also love Django so, naturally, we love Python.

How to Get Things 3D Printed Without a Printer

3D printing without a printer3D printing without a printer
No printer? No problem.
Zach Zach (232)
Total time: 5 minutes 
Updated: July 22nd, 2020
Calling all writers!

Are you a writer who loves 3D printing? Send us a message

Want to build a cool project but it requires a 3D-printed part? No worries! There are tons of ways to get a 3D model printed without having a printer. This short guide will show you some of your options.

Posted in these interests:

3dprinting
PRIMARY
55 guides
Using a 3D printing serviceUsing a 3D printing service

Many online services such as Sculpteo exist that will print your model and ship it to you. You pay a small fee based on the size and complexity of the model, choose your print colors, and receive the model in just a few days.

3D printing at a makerspace3D printing at a makerspace
3D printing at the Tampa Hackerspace.

A hackerspace, or “makerspace”, is a private organization comprised of members who share a shared workspace and, generally, the interest of building things.

Chances are there’s one near you. Members normally pay a monthly fee, but most have “Open Make Nights” where you can pop in and use the equipment without needing a membership. You can find your local hackerspace using this tool, which lists over 2,000 hackerspaces.

Library 3D printingLibrary 3D printing
3D printers at the Libbie Mill Library.

In an effort to remain a relevant community resource, many public libraries now have 3D printers available for use! Find your local library and call the information desk to ask if they have any 3D printers available.

If you’re a student, your university can likely provide you with access to one. Call your university library’s information desk and they can direct you to the college/department that will give you access.

Many 3D printing businesses and professionals advertise their printing services on Craigslist. Most charge you when you pick up the model. Be sure to ask for references or photos of their work.

Budget Ender 3 3D printerBudget Ender 3 3D printer

If cost is the primary reason you don’t have a 3D printer, you may not know how low prices have gotten. In the last few years, 3D printers have come way down in price. I picked up my Creality Ender 3 for $179 on GearBest. I also wrote a full Ender 3 review if you want to check it out!

We’re hiring!
Are you a passionate writer or editor? We want to hear from you!

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Total time: 5 minutes 
Updated: July 22nd, 2020
python
PRIMARY
67 guides
code
68 guides
Calling all writers!

We’re hiring. Write for Howchoo

python
PRIMARY
67 guides
code
68 guides
Calling all writers!

We’re hiring. Write for Howchoo

Tyler's profile pictureTyler
Joined in 2015
Software Engineer and creator of howchoo.
Get the latest edition of Python in just minutes.
Ash's profile picture AshView
In these interests: codewindowspython
Run Python scripts in command prompt without typing the whole path.
Ash's profile picture AshView
In these interests: windowscodepython
You can run any Python script in a command-line interface.
Ash's profile picture AshView
In these interests: python
Got a Python question? We’ve probably answered it here.
Not sure what version of Python you’re running? Time to find out!
Python is a very popular programming language for data visualization.
Slack has become one of the most important tools for communication in many companies, mine included.
If you’re familiar with Python’s keyword-only arguments, then you’ve probably wondered why the same constraint doesn’t exist for positional arguments. This changes with Python 3.
Specify a parallel filesystem cache for compiled bytecode
Learn how to use formatted string literals in Python
While this requirement may seem rare, learning how to nest defaultdicts properly in Python can be extremely powerful and save you from bloated and confusing initialization code.
In Python, we often run into scenarios where we need to merge two or more lists. This is also called list concatenation, and Python provides multiple methods for accomplishing this.
python
PRIMARY
Python is howchoo’s favorite programming language. We believe python promotes the most organized and performant codebase possible. We also love Django so, naturally, we love Python.
Code is poetry — one line at a time.

Python Dictionary Comprehension (With Examples)

Tyler Tyler (282)
Total time: 5 minutes 
Updated: July 22nd, 2020

In Python, comprehensions are a useful construct that allows us to create new sequences in a very concise way. Many people are familiar with Python list comprehension, but the comprehension syntax can be used to create dictionaries as well. In this guide, I’ll explain the syntax, walk through a few examples of how dictionary comprehension works, and show how it can be used to simplify your code.

Posted in these interests:

python
PRIMARY
66 guides
code
67 guides

If you’re new to comprehensions, this syntax might be a little confusing. So I’ll break it down:

{key: value for x in iterable}

A conditional can optionally included like this:

new_dict = {key: value for x in iterable if condition}

In many use cases, the elements in the iterable will provide the key and value, but it’s not required. We iterate over iterable assigning each item to the variable x. Then the new dictionary is formed using the variables key and value.

Here’s a simple example:

> {str(x): x for x in range(3)} {'0': 0, '1': 1, '2': 2}

The following shows how our example maps to the syntax instruction from above.

Syntax Example
key str(x)
value x
iterable range(3)

In the remainder of this guide, I’ll provide examples of how dictionary comprehensions can be used to improve your code.

Sometimes we have a list of dictionaries, and we need to lookup a dictionary by a particular key. This can be the case with database query results or data read from a csv.

Goal: Convert a list of dictionaries to a nested dictionary, so we can look up elements by their id.

The initial data is structured like this:

data_list = [ {'id': '1', 'name': ...}, {'id': '2', 'name': ...}, {'id': '3', 'name': ...}, ... ]

If we need to lookup rows by id, we could search the list, but that would be inefficient for multiple lookups. A better way is to convert the list of dictionaries to a dictionary, where the key is the id.

data_dict = { '1': {'id': '1', 'name': ...}, '2': {'id': '2', 'name': ...}, '3': {'id': '3', 'name': ...}, }

Now we can easily and efficiently lookup dictionaries by their id.

some_dict = data_dict[id]

So how do we accomplish this?

Using a for loop

data_dict = {} for item in data_list: data_dict[item['id']] = item

We iterate over the list, grabbing the id from each item. Then we create a new dictionary key and value during each iteration.

This is not too bad, but we can simplify even more using dictionary comprehension.

Using dictionary comprehension

data_dict = {d['id']: d for d in data_list}

Hopefully you can see how both examples accomplish the same thing. They both include the same components, but the second example is cleaner.

Suppose we have a dictionary with many key-value pairs, and we want to copy that dictionary and filter out specific values.

Goal: Create a dictionary of U.S. state data including only states established on or after 1900.

Our initial dictionary contains data for all 50 U.S. states. It looks like this:

state_data = { 'Alabama': { 'Abbreviation': 'AL', 'Capital': 'Montgomery', 'Established': 1819 }, 'Alaska': { 'Abbreviation': 'AK', 'Capital': 'Juneau', 'Established': 1959 }, ... }

So we want to filter our dictionary and include only states that were established on or after 1900.

Using a for loop

states_after_1900 = {} for k, v in state_data.items(): if v['Established'] >= 1900: states_after_1900[k] = v

This gives us the answer we’d like, but with dictionary comprehensions we can accomplish this in a single line of code.

Using dictionary comprehension

states_after_1900 = {k: v for k, v in state_data.items() if v['Established'] >= 1900}

Notice this includes all of the same components, but it’s much more concise.

The results

In order to conserve space, while still proving this worked as expected, I’ll just print the state and the date it was established:

for k, v in states_after_1900.items(): print(k, v['Established']) # => Output Alaska 1959 Arizona 1912 Hawaii 1959 New Mexico 1912 Oklahoma 1907

In some cases, we start with a dictionary that is structured in a specific way, but we need the values to be transformed.

I’m going to use a contrived example to demonstrate how this works. Suppose we have a dictionary, where the key is a user id, and the value is the user’s first name. For some reason, we want to display the users names in reverse, possibly multiple times. We could use the extended slice operator or the reversed function as needed, but that could be wasteful if we’re planning on doing this multiple times for each name. Another option is to create a new dictionary where the names are reversed.

Note: For more details on reversing strings in Python check out our guide.

Here’s the initial names dictionary.

names = { 1: 'Sam', 2: 'Clark', 3: 'Carol', ... }

We’ll create a new dictionary where each value is mapped to it’s reverse.

Using a for loop

names_reversed = {} for k, v in names.items(): names_reversed[k] = v.reversed()

Using dictionary comprehension

names_reversed = {k: v[::-1] for k, v in names.items()}

Results

names_reversed => Output {1: 'maS', 2: 'kralC', 3: 'loraC'}
We’re hiring!
Are you a passionate writer or editor? We want to hear from you!

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

How to List All Loaded Apache Modules

Tyler Tyler (282)
Total time: 2 minutes 
Updated: July 22nd, 2020

This short guide will show you how to list all loaded modules in Apache. This guide assumes that apache (httpd) is installed and running.

Posted in these interests:

webdev
PRIMARY
58 guides
sysadmin
12 guides
apache
1 guide

In Terminal, or your Unix command line, use the following command:

httpd -M 

You should see output similar to this:

core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) auth_basic_module (shared) auth_digest_module (shared) 

This is a list of all loaded Apache modules.

We’re hiring!
Are you a passionate writer or editor? We want to hear from you!

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Total time: 5 minutes 
Updated: July 22nd, 2020
python
PRIMARY
67 guides
code
68 guides
Calling all writers!

We’re hiring. Write for Howchoo

python
PRIMARY
67 guides
code
68 guides
Calling all writers!

We’re hiring. Write for Howchoo

Tyler's profile pictureTyler
Joined in 2015
Software Engineer and creator of howchoo.
Get the latest edition of Python in just minutes.
Ash's profile picture AshView
In these interests: codewindowspython
Run Python scripts in command prompt without typing the whole path.
Ash's profile picture AshView
In these interests: windowscodepython
You can run any Python script in a command-line interface.
Ash's profile picture AshView
In these interests: python
Got a Python question? We’ve probably answered it here.
Not sure what version of Python you’re running? Time to find out!
Python is a very popular programming language for data visualization.
In Python, comprehensions are a useful construct that allows us to create new sequences in a very concise way.
Slack has become one of the most important tools for communication in many companies, mine included.
If you’re familiar with Python’s keyword-only arguments, then you’ve probably wondered why the same constraint doesn’t exist for positional arguments. This changes with Python 3.
Learn how to use formatted string literals in Python
While this requirement may seem rare, learning how to nest defaultdicts properly in Python can be extremely powerful and save you from bloated and confusing initialization code.
In Python, we often run into scenarios where we need to merge two or more lists. This is also called list concatenation, and Python provides multiple methods for accomplishing this.
python
PRIMARY
Python is howchoo’s favorite programming language. We believe python promotes the most organized and performant codebase possible. We also love Django so, naturally, we love Python.
Code is poetry — one line at a time.

How to Open URLs in Google Chrome from the macOS Terminal

Tyler Tyler (285)
Total time: 5 minutes 
Updated: July 22nd, 2020

If you spend any amount of time working on the command line in macOS, you’ll eventually want to automate the process of opening URLs in your favorite browser. In this guide, we’ll learn how to open Chrome from the command line (or a shell script) on macOS.

In the following steps, we’ll learn a few variations of the open command to learn how to:

  • Bring the Chrome window into focus
  • Open a specific URL in Chrome
  • Open a URL in a specific Chrome profile

Posted in these interests:

macos
PRIMARY
40 guides
chrome
16 guides
bash
5 guides

The open command accepts a -a option that allows us to specify which application we want to open.

So if you just want to open Google Chrome from the command line, it’s as simple as this:

open -a "Google Chrome"

This will do nothing more than bring the Google Chrome window into focus.

To open a specific URL in Chrome, simply pass the URL as the first argument of the command, like this:

open -a "Google Chrome" 

This will open your favorite website in your favorite browser.

Google About Version get profile directoryGoogle About Version get profile directory

If you’re like me and use multiple Chrome profiles, you’ll want to be able to specify which profile to use when opening the URL. For this, we’ll have to move away from the convenient open command.

Before we get to the command, we’ll need to figure out the correct profile directory to use. Sadly, this will not be the same value as your profile name. To get your profile directory, open Chrome in the profile you want to use and navigate to chrome://version/. Find the item labeled Profile Path, and copy only the last part of the path. In my case, it’s Profile 5.

/Applications/Google Chrome.app/Contents/MacOS/Google Chrome  --profile-directory=Profile 5

I know its not realistic to type this every time you want to open a URL. You could bake this into a script or see the next step where I’ll cover using aliases and bash functions to make this less painful.

If you’re going to open URLs frequently, there are a few ways to dramatically increase efficiency. The easiest way is to use bash aliases. An alias allows you to basically create a shortcut for longer commands.

Alias for opening URLs in Chrome

Here are a few examples (you can add them to your ~/.bash_profile).

alias gc="open -a Google Chrome"

Or if you’d like to create an alias to the command that let’s you specify a profile, you could do the following:

alias gc="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --profile-directory=Profile 5"

Anytime you edit your bash_profile, you need to run source ~/.bash_profile or open a new shell to see the changes take effect.

With this, you can run:

gc # Open or focus on the Chrome window gc  # Open the url in Chrome

Similarly, the gc {url} command will open the url in Chrome, but it will use the specified profile every time.

Alias that accepts a URL from STDIN

In some cases, you might want to accept a URL from STDIN. The open command handles stdin the way we’d like, so if you’re using the first alias, you don’t need to do anything.

If you’re using the alias for Google Chrome, one easy way is to create a second alias (using xargs) like this:

alias gcx="xargs /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --profile-directory=Profile 5"

This will allow you to do something like this:

echo "" | gcx

If you’ve got a better way of doing this, let me know in the comments below 🙂

We’re hiring!
Are you a passionate writer? We want to hear from you!

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Updated: July 22nd, 2020
tea
PRIMARY
2 guides
food
17 guides
Calling all writers!

We’re hiring. Write for Howchoo

tea
PRIMARY
2 guides
food
17 guides
Check PriceTea Kettle with a Stainless Steel Infuser
Tea Kettle with a Stainless Steel Infuser
on Amazon
Check PriceTea Mug
Tea Mug
on Amazon
Check PriceReusable Tea Bags
Reusable Tea Bags
on Amazon
Check PriceTea Organizer
Tea Organizer
on Amazon
Check PriceMug warmer
Mug warmer
on Amazon
Check PriceTravel mug
Travel mug
on Amazon
Check PriceTea infuser
Tea infuser
on Amazon
Calling all writers!

We’re hiring. Write for Howchoo

Tayler's profile pictureTayler
Joined in 2020
I like coffee, cats, video games, weird instruments, and unique prose. I sometimes write decent things.
Ever wondered how to make Chai at home? Tired of the fake chai tea latte served by Starbucks and the likes? Here’s a complete how-to guide to get invigorating tea right in your own kitchen.
Avni 's profile picture Avni View
In these interests: teahandcraftedchai
For the most caffeinated coffee consumers.
Tayler's profile picture TaylerView
In these interests: foodcoffee
In these interests: recipesfood
Easy biscuits are just minutes away.
Nutella has never been tastier.
Save your bananas in the tastiest way.
The easiest peanut butter cookie recipe you’ll find.
Don’t settle for gummy, mushy rice.
Don’t throw away that day-old baguette!
The pizza peel that comes with the Uuni is a workable first pizza peel, but after a few pizzas, I really wanted a handle. I decided to add a handle using a simple 1″ dowel rod. Here’s how I did it!
Fire up the summer with a new Pi project.
I don’t know why I didn’t think of this sooner, but replacing the milk/cream with buttermilk in homemade frosting is seriously amazing. It’s not obviously tangy.
tea
PRIMARY
Foodies assemble!