Tutorial by Examples

the timedelta module comes in handy to compute differences between times: from datetime import datetime, timedelta now = datetime.now() then = datetime(2016, 5, 23) # datetime.datetime(2016, 05, 23, 0, 0, 0) Specifying time is optional when creating a new datetime object delta = now-then ...
To remove extraneous packages (packages that are installed but not in dependency list) run the following command: npm prune To remove all dev packages add --production flag: npm prune --production More on it
To generate a list (tree view) of currently installed packages, use npm list ls, la and ll are aliases of list command. la and ll commands shows extended information like description and repository. Options The response format can be changed by passing options. npm list --json json - Sh...
The PieChart class draws data in the form of circle which is divided into slices. Every slice represents a percentage (part) for a particular value. The pie chart data is wrapped in PieChart.Data objects. Each PieChart.Data object has two fields: the name of the pie slice and its corresponding valu...
When using a VCS such as Git or SVN, there are some secret data that must never be versioned (whether the repository is public or private). Among those data, you find the SECRET_KEY setting and the database password. A common practice to hide these settings from version control is to create a file...
The try { ... } catch ( ... ) { ... } control structure is used for handling Exceptions. String age_input = "abc"; try { int age = Integer.parseInt(age_input); if (age >= 18) { System.out.println("You can vote!"); } else { System.out.println(...
Since npm itself is a Node.js module, it can be updated using itself. If OS is Windows must be running command prompt as Admin npm install -g npm@latest If you want to check for updated versions you can do: npm outdated In order to update a specific package: npm update <package name>...
Specific to Windows System and android Phone: Requirements: USB Cable Android Device Android Driver Software Basically after connecting USB cable PC detects the Android Device and it will automatically search for the required Drivers for that Android Device. If that drivers are not found th...
Removing duplicate values in a list can be done by converting the list to a set (that is an unordered collection of distinct objects). If a list data structure is needed, then the set can be converted back to a list using the function list(): names = ["aixk", "duke", "edik&...
A closure is the PHP equivalent of an anonymous function, eg. a function that does not have a name. Even if that is technically not correct, the behavior of a closure remains the same as a function's, with a few extra features. A closure is nothing but an object of the Closure class which is create...
It is possible, inside a closure, to use an external variable with the special keyword use. For instance: <?php $quantity = 1; $calculator = function($number) use($quantity) { return $number + $quantity; }; var_dump($calculator(2)); // Shows "3" You can go further by ...
As seen previously, a closure is nothing but an instance of the Closure class, and different methods can be invoked on them. One of them is bindTo, which, given a closure, will return a new one that is bound to a given object. For example: <?php $myClosure = function() { echo $this->p...
Let's consider this example: <?php $myClosure = function() { echo $this->property; }; class MyClass { public $property; public function __construct($propertyValue) { $this->property = $propertyValue; } } $myInstance = new MyClass('Hello world...
Since PHP7, it is possible to bind a closure just for one call, thanks to the call method. For instance: <?php class MyClass { private $property; public function __construct($propertyValue) { $this->property = $propertyValue; } } $myClosure = function() ...
In general, an observer is a class with a specific method being called when an action on the observed object occurs. In certain situations, closures can be enough to implement the observer design pattern. Here is a detailed example of such an implementation. Let's first declare a class whose purpos...
We define two sets a and b >>> a = {1, 2, 2, 3, 4} >>> b = {3, 3, 4, 4, 5} NOTE: {1} creates a set of one element, but {} creates an empty dict. The correct way to create an empty set is set(). Intersection a.intersection(b) returns a new set with elements present in bot...
This example creates a simple 1-column repeater that displays a list of numbers, one per repeater item. Markup: <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <%# Container.DataItem.ToString() %> </ItemTemplate> </Repe...
Even though Python natively supports big integers, taking the nth root of very large numbers can fail in Python. x = 2 ** 100 cube = x ** 3 root = cube ** (1.0 / 3) OverflowError: long int too large to convert to float When dealing with such large integers, you will need to use a custom f...
A git repository is an on-disk data structure which stores metadata for a set of files and directories. It lives in your project's .git/ folder. Every time you commit data to git, it gets stored here. Inversely, .git/ contains every single commit. It's basic structure is like this: .git/ obj...
git is fundamentally a key-value store. When you add data to git, it builds an object and uses the SHA-1 hash of the object's contents as a key. Therefore, any content in git can be looked up by it's hash: git cat-file -p 4bb6f98 There are 4 types of Object: blob tree commit tag

Page 330 of 1336