_.map is useful for changing a list into a different list in a purely
declarative way. Rather than using imperative techniques like a while or
for loop in javascript, you can just specify how you want to manipulate an
element of a list and
Use _.map to make a new list transformed by the functio...
We can assert some predicate over a collection using _.some to check if there
is at least one member of a collection that meets some criteria. This is great
when writing business logic to assert certain conditions on a group of objects.
For example, let's say you wanted to make sure at least one...
In medical imaging, spectroscopy, image processing, cryptography and other areas of science and engineering it is often the case that one wishes to compute multidimensional Fourier transforms of images. This is quite straightforward in Matlab: (multidimensional) images are just n-dimensional matrice...
To copy files from the build context in a Docker image, use the COPY instruction:
COPY localfile.txt containerfile.txt
If the filename contains spaces, use the alternate syntax:
COPY ["local file", "container file"]
The COPY command supports wildcards. It can be used for ...
To declare exposed ports from a Dockerfile use the EXPOSE instruction:
EXPOSE 8080 8082
Exposed ports setting can be overridden from the Docker commandline but it is a good practice to explicitly set them in the Dockerfile as it helps understand what an application does.
Group common operations
Docker builds images as a collection of layers. Each layer can only add data, even if this data says that a file has been deleted. Every instruction creates a new layer. For example:
RUN apt-get -qq update
RUN apt-get -qq install some-package
Has a couple of downsides:
...
_mycompletion() {
local command_name="$1" # not used in this example
local current_word="$2"
local previous_word="$3" # not used in this example
# COMPREPLY is an array which has to be filled with the possible completions
# compgen is used to fi...
It is possible to save a Docker container's filesystem contents to a tarball archive file. This is useful in a pinch for moving container filesystems to different hosts, for example if a database container has important changes and it isn't otherwise possible to replicate those changes elsewhere. Pl...
Search engines won't index your products if you have a URL like the following:
http://www.yourdomain.com/product.php?id=123
SEO friendly URL would look like http://www.yourdomain.com/123/product-name/. The following code helps achieve this without having to change product.php code.
RewriteEng...
3.0
The most simple way is to use sorted():
let words = ["Hello", "Bonjour", "Salute", "Ahola"]
let sortedWords = words.sorted()
print(sortedWords) // ["Ahola", "Bonjour", "Hello", "Salute"]
or sort()
var mutable...
The method compareTo should be used to compare BigDecimals:
BigDecimal a = new BigDecimal(5);
a.compareTo(new BigDecimal(0)); // a is greater, returns 1
a.compareTo(new BigDecimal(5)); // a is equal, returns 0
a.compareTo(new BigDecimal(10)); // a is less, returns -1
Commonly you shou...
GCD provides mechanism for performing a loop, whereby the loops happen concurrently with respect to each other. This is very useful when performing a series of computationally expensive calculations.
Consider this loop:
for index in 0 ..< iterations {
// Do something computationally expens...
A powerful alternative to virtualenv is Anaconda - a cross-platform, pip-like package manager bundled with features for quickly making and removing virtual environments. After installing Anaconda, here are some commands to get started:
Create an environment
conda create --name <envname> pyth...
Query syntax and method syntax are semantically identical, but many people find query syntax simpler and easier to read. Let’s say we need to retrieve all even items ordered in ascending order from a collection of numbers.
C#:
int[] numbers = { 0, 1, 2, 3, 4, 5, 6 };
// Query syntax:
IEnumerab...
A HAVING clause filters the results of a GROUP BY expression. Note: The following examples are using the Library example database.
Examples:
Return all authors that wrote more than one book (live example).
SELECT
a.Id,
a.Name,
COUNT(*) BooksWritten
FROM BooksAuthors ba
INNER JOIN Aut...
We can use 1,2,3.. to determine the type of order:
SELECT * FROM DEPT
ORDER BY
CASE DEPARTMENT
WHEN 'MARKETING' THEN 1
WHEN 'SALES' THEN 2
WHEN 'RESEARCH' THEN 3
WHEN 'INNOVATION' THEN 4
ELSE 5
END,
CITY
IDREGIONCITYDEPARTMENTEMPLOYEES_N...
When results need to have some logic applied 'on the fly' one can use CASE statement to implement it.
SELECT CASE WHEN Col1 < 50 THEN 'under' ELSE 'over' END threshold
FROM TableName
also can be chained
SELECT
CASE WHEN Col1 < 50 THEN 'under'
WHEN Col1 > 50 AND Col1 ...