Tutorial by Examples: du

A module is a file containing Python definitions and statements. Function is a piece of code which execute some logic. >>> pow(2,3) #8 To check the built in function in python we can use dir(). If called without an argument, return the names in the current scope. Else, return an alph...
A function defined as async is a function that can perform asynchronous actions but still look synchronous. The way it's done is using the await keyword to defer the function while it waits for a Promise to resolve or reject. Note: Async functions are a Stage 4 ("Finished") proposal on tr...
A context manager is an object that is notified when a context (a block of code) starts and ends. You commonly use one with the with statement. It takes care of the notifying. For example, file objects are context managers. When a context ends, the file object is closed automatically: open_file = ...
use Data::Dumper; my $data_structure = { foo => 'bar' }; print Dumper $data_structure; Using Data::Dumper is an easy way to look at data structures or variable content at run time. It ships with Perl and you can load it easily. The Dumper function returns the data structure serialized in a...
Sometimes Data::Dumper is not enough. Got a Moose object you want to inspect? Huge numbers of the same structure? Want stuff sorted? Colored? Data::Printer is your friend. use Data::Printer; p $data_structure; Data::Printer writes to STDERR, like warn. That makes it easier to find the outpu...
When defining discriminated unions you can name elements of tuple types and use these names during pattern matching. type Shape = | Circle of diameter:int | Rectangle of width:int * height:int let shapeIsTenWide = function | Circle(diameter=10) | Rectangle(width=10) -> t...
$sku = 'sku-goes-here'; $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
$id = 1; $product = Mage::getModel('catalog/product')->load($id); if($product->getId()){ //product was found }
$collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToFilter('sku', array('like' => 'UX%'));
$collection = Mage::getModel('catalog/product')->getCollection(); // Using operator $collection->addAttributeToFilter('status', array('eq' => 1)); // Without operator (automatically uses 'equal' operator $collection->addAttributeToFilter('status', 1);
Inject and reduce are different names for the same thing. In other languages these functions are often called folds (like foldl or foldr). These methods are available on every Enumerable object. Inject takes a two argument function and applies that to all of the pairs of elements in the Array. For...
Discriminated unions in F# offer a a way to define types which may hold any number of different data types. Their functionality is similar to C++ unions or VB variants, but with the additional benefit of being type safe. // define a discriminated union that can hold either a float or a string type...
Module is a collection of type declarations, data declarations and procedures. The basic syntax is: module module_name use other_module_being_used ! The use of implicit none here will set it for the scope of the module. ! Therefore, it is not required (although considered good practice...
Artisan is a utility that can help you do specific repetitive tasks with bash commands. It covers many tasks, including: working with database migrations and seeding, clearing cache, creating necessary files for Authentication setup, making new controllers, models, event classes, and a lot more. ...
--- trim: a string-trimming module for Lua -- Author, date, perhaps a nice license too -- -- The code here is taken or adapted from material in -- Programming in Lua, 3rd ed., Roberto Ierusalimschy -- trim_all(string) => return string with white space trimmed on both sides local trim_al...
-- The following assumes that trim module is installed or in the caller's package.path, -- which is a built-in variable that Lua uses to determine where to look for modules. local trim = require "trim" local msg = " Hello, world! " local cleaned = trim.trim_all(msg)...
A std::vector automatically increases its capacity upon insertion as needed, but it never reduces its capacity after element removal. // Initialize a vector with 100 elements std::vector<int> v(100); // The vector's capacity is always at least as large as its size auto const old_capacity...
To start coding in the first place, you have to right click your VBA Project in the left list and add a new Module. Your first Hello-World Code could look like this: Sub HelloWorld() MsgBox "Hello, World!" End Sub To test it, hit the Play-Button in your Toolbar or simply hit the...
What is a node.js module (link to article): A module encapsulates related code into a single unit of code. When creating a module, this can be interpreted as moving all related functions into a file. Now lets see an example. Imagine all files are in same directory: File: printer.js "use...
Procedures do something. Name them after what they're doing, using a verb. If accurately naming a procedure is not possible, likely the procedure is doing too many things and needs to be broken down into smaller, more specialized procedures. Some common VBA naming conventions go thus: For all Pr...

Page 5 of 47