How do I remove a submodule?

In modern git (I’m writing this in 2022, with an updated git installation), this has become quite a bit simpler: Run git rm <path-to-submodule>, and commit. This removes the filetree at <path-to-submodule>, and the submodule’s entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed. As the docs … Read more

What are the differences between a HashMap and a Hashtable in Java?

There are several differences between HashMap and Hashtable in Java: Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values. One of HashMap’s … Read more

How do I copy to the clipboard in JavaScript?

Overview There are three primary browser APIs for copying to the clipboard: Async Clipboard API [navigator.clipboard.writeText] Text-focused portion available in Chrome 66 (March 2018) Access is asynchronous and uses JavaScript Promises, can be written so security user prompts (if displayed) don’t interrupt the JavaScript in the page. Text can be copied to the clipboard directly … Read more

How is Docker different from a virtual machine?

Docker originally used LinuX Containers (LXC), but later switched to runC (formerly known as libcontainer), which runs in the same operating system as its host. This allows it to share a lot of the host operating system resources. Also, it uses a layered filesystem (AuFS) and manages networking. AuFS is a layered file system, so … Read more

How to close/hide the Android soft keyboard programmatically?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your focused view. // Check if no view has focus: View view = this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } This will force the keyboard to be … Read more

The Definitive C++ Book Guide and List

Beginner Introductory, no previous programming experience Book Author(s) Description review C++ Primer* * Not to be confused with C++ Primer Plus (Stephen Prata), with a significantly less favorable review. Stanley Lippman, Josée Lajoie, and Barbara E. Moo (updated for C++11) Coming at 1k pages, this is a very thorough introduction into C++ that covers just … Read more

Change a HTML5 input’s placeholder color with CSS

Implementation There are three different implementations: pseudo-elements, pseudo-classes, and nothing. WebKit, Blink (Safari, Google Chrome, Opera 15+) and Microsoft Edge are using a pseudo-element: ::-webkit-input-placeholder. [Ref] Mozilla Firefox 4 to 18 is using a pseudo-class: :-moz-placeholder (one colon). [Ref] Mozilla Firefox 19+ is using a pseudo-element: ::-moz-placeholder, but the old selector will still work for … Read more

Understanding slicing

The syntax is: a[start:stop] # items start through stop-1 a[start:] # items start through the rest of the array a[:stop] # items from the beginning through stop-1 a[:] # a copy of the whole array There is also the step value, which can be used with any of the above: a[start:stop:step] # start through not … Read more