Tutorial by Examples: e

In javascript, assigning a non-primitive value (Such as Object, Array, Function, and many more), keeps a reference (an address in the memory) to the assigned value. Assigning a primitive value (String, Number, Boolean, or Symbol) to two different variables, and changing one, won't change both: var...
Be careful, this approach might be considered as a bad design for angular apps, since it requires programmers to remember both where functions are placed in the scope tree, and to be aware of scope inheritance. In many cases it would be preferred to inject a service (Angular practice - using scope ...
CSS resets take separate approaches to browser defaults. Eric Meyer’s Reset CSS has been around for a while. His approach nullifies many of the browser elements that have been known to cause problems right off the back. The following is from his version (v2.0 | 20110126) CSS Reset. html, body, di...
string strCmdText = "/C copy /b Image1.jpg + Archive.rar Image2.jpg"; System.Diagnostics.Process.Start("CMD.exe",strCmdText); This is to hide the cmd window. System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo...
int[string] wordCount(string[] wordList) { int[string] words; foreach (word; wordList) { words[word]++; } return words; } void main() { int[string] count = wordCount(["hello", "world", "I", "say", "hello"]); ...
_.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...
Filtering a list down to only the elements we want to do. Lodash provides a function called _.filter filters elements based on the predicate function you provide. A predicate is a function that takes data in and returns either true or false. Let's look at how we'd get just the even numbers from...
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...
Reducing a list to a single value is easy when you have _.reduce. Let's say we wanted to see if a group of people could afford a cab ride. We'd want to look at all the money they have together as a group, which means we'd want to reduce a list of objects to a single value, in this case the sum ...
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...
A minimal Dockerfile looks like this: FROM alpine CMD ["echo", "Hello StackOverflow!"] This will instruct Docker to build an image based on Alpine (FROM), a minimal distribution for containers, and to run a specific command (CMD) when executing the resulting image. Build an...
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...
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC] RewriteRule \.(gif|jpg|css)$ - [F] This blocks all the links to '.gif', '.jpg' and '.css' files which are not from the domain name http://www.yourdomain.com. Display alterna...
import fileinput replacements = {'Search1': 'Replace1', 'Search2': 'Replace2'} for line in fileinput.input('filename.txt', inplace=True): for search_for in replacements: replace_with = replacements[search_for] line = line.replace(search_for, replace_with...
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...

Page 364 of 1191