copy

How to copy text from the MacOS Terminal to the clipboard

If you ever need to copy text (or a text file) from the MacOS Terminal to the Mac clipboard, I can confirm that the Mac pbcopy command works. It reads from STDIN and copies the text to the clipboard, so commands like these work:

$ echo "foo bar baz" | pbcopy

$ cat /etc/passwd | pbcopy
How to use the Linux ‘scp’ command without a password to make remote backups alvin July 2, 2016 - 6:11pm

Summary: How to create a public and private key pair to use ssh and scp without using a password, which lets you automate a remote server backup process.

Over the last two years I've ended up creating a large collection of websites and web applications on a variety of Linux servers that are hosted with different companies like GoDaddy and A2 Hosting. I recently embarked on a mission to automate the backup processes for all these sites, and as a result of this effort, I thought I'd share what I've learned here.

How to paste and load blocks of code in the Scala REPL

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.2, “How to paste and load blocks of code in the Scala REPL.”

Problem

You want to experiment with some code in the Scala REPL, and typing it in or trying to paste it into the REPL won’t work.

How to copy files to an Android emulator’s data directory with 'adb push'

As an Android developer, you can normally use the adb push command to copy files from your computer’s hard drive to an Android device. However, I just ran into a problem where I couldn’t copy files to my Android emulator’s “data” directory, i.e., the /data/data filesystem. When I tried to copy a file using this command:

$ adb push foo.jpg /data/data/com.alvinalexander.myapp/files

I got this Android error:

A Scala case class copy method example

Scala FAQ: When you create a case class in Scala, a copy method is generated for your case class. What does this copy method do?

In short, it lets you make a copy of an object, where a “copy” is different than a clone, because with a copy you can change fields as desired during the copying process. The copy method is important in functional programming, where values (val) are immutable.

A Java deep clone (deep copy) example

While interviewing for computer programming positions in Boulder, Colorado, I found that most interviewers ask questions about Java serialization. After being asked about serialization for the third time recently, I suddenly remembered an old Java deep clone hack that takes advantage of serialization.

The basic idea is this: