Tutorial by Examples: f

Reading a text file line-by-line A proper way to read a text file line-by-line till the end is usually not clear from ifstream documentation. Let's consider some common mistakes done by beginner C++ programmers, and a proper way to read the file. Lines without whitespace characters For the sake o...
The try...catch...finally statement combines exception handling with clean-up code. The finally block contains code that will be executed in all circumstances. This makes them suitable for resource management, and other kinds of cleanup. Try-finally Here is an example of the simpler (try...finally...
Given a simple sitecore item: Item item; The item itself does not contain it's url. To obtain a url for an item you need to make a call to the static class Sitecore.Links.LinkManager string url = LinkManager.GetItemUrl(item); an overload of this accepts a UrlOptions class: UrlOptions option...
Mage::getSingleton('customer/session')->isLoggedIn()
First we must edit the SSH daemon config file. Though under different Linux distributions this may be located in different directories, usually it is stored under /etc/ssh/sshd_config Use your text editor to change the values set in this file, all lines starting with # are commented out and must ha...
The passport-facebook module is used to implement a Facebook authentication. In this example, if the user does not exist on sign-in, he is created. Implementing strategy : const passport = require('passport'); const FacebookStrategy = require('passport-facebook').Strategy; // Strategy is name...
Since ls() finds objects by names, it's a handy way to find out if an object is present in the scene. ls() with a list of objects will only return the ones which are in the scene. available_characters = cmds.ls('fred', 'barney', 'wilma', 'dino') # available_characters will contain only the named...
The pattern parameter_pack ... is expanded into a list of comma-separated substitutions of parameter_pack with each one of its parameters template<class T> // Base of recursion void variadic_printer(T last_argument) { std::cout << last_argument; } template<class T, class .....
MediaTypeFormatter is an abstract class from which JsonMediaTypeFormatter and XmlMediaTypeFormatter classes inherit from. Here, JsonMediaTypeFormatter class handles JSON objects and XmlMediaTypeFormatter class handles XML objects. Return only JSON irrespective of the Accept Header value: To return...
CREATE OR REPLACE TRIGGER CORE_MANUAL_BIUR BEFORE INSERT OR UPDATE ON CORE_MANUAL FOR EACH ROW BEGIN if inserting then -- only set the current date if it is not specified if :new.created is null then :new.created := sysdate; end if; end if; -- always s...
Some functions in R produce a side effect (i.e. saving, printing, plotting, etc) and do not always return a meaningful or desired value. %T>% (tee operator) allows you to forward a value into a side-effect-producing function while keeping the original lhs value intact. In other words: the tee op...
Installation Using apt on Debian based systems sudo apt-get install php5-imagick Using Homebrew on OSX/macOs brew install imagemagick To see the dependencies installed using the brew method, visit brewformulas.org/Imagemagick. Using binary releases Instructions on imagemagick website. Us...
Generators are fast coded and in many cases a slim alternative to heavy iterator-implementations. With the fast implementation comes a little lack of control when a generator should stop generating or if it should generate something else. However this can be achieved with the usage of the send() fu...
For giving short names to a data type Instead of: long long int foo; struct mystructure object; one can use /* write once */ typedef long long ll; typedef struct mystructure mystruct; /* use whenever needed */ ll foo; mystruct object; This reduces the amount of typing needed if the ...
To switch focus to either main document or first frame of the page. You have to use below syntax. webDriver.SwitchTo().DefaultContent();
for ([declaration-or-expression]; [expression2]; [expression3]) { /* body of the loop */ } In a for loop, the loop condition has three expressions, all optional. The first expression, declaration-or-expression, initializes the loop. It is executed exactly once at the beginning of the lo...
A loop is said to be an infinite loop if the control enters but never leaves the body of the loop. This happens when the test condition of the loop never evaluates to false. Example: C99 for (int i = 0; i >= 0; ) { /* body of the loop where i is not changed*/ } In the above example...
Player playerToHide; Player playerToNotSee; playerToNotSee.hide(playerToHide); //playerToHide will no longer be seen by playerToNotSee. If player is already hidden, nothing happens
Player playerToCheck; Player playerSeeing; boolean isVisible = playerSeeing.canSee(playerToCheck); //isVisible returns true if playerSeeing can see playerToCheck and false otherwhise
This can be done by using the event EntityTargetEvent Entities won't target the player if you cancel the event: @EventHandler public void onEntityTarget(EntityTargetEvent e) { Entity target = e.getEntity(); if(target instanceof Player) { Player playerTargetted = (Player) target...

Page 343 of 457