Tutorial by Examples

Set a convenience method in your base model namespace Base; class Model extends \Phalcon\Mvc\Model { public function sanitize($attr, $filterName) { $filter = $this->getDI()->get('filter'); $this->$attr = $filter->sanitize($this->$attr, $filterName); ...
The fold method iterates over a collection, using an initial accumulator value and applying a function that uses each element to update the accumulator successfully: val nums = List(1,2,3,4,5) var initialValue:Int = 0; var sum = nums.fold(initialValue){ (accumulator,currentElementBeingIterated...
Scala has a powerful type-inference mechanism built-in to the language. This mechanism is termed as 'Local Type Inference': val i = 1 + 2 // the type of i is Int val s = "I am a String" // the type of s is String def squared(x : Int) = x*x // the return type ...
The Scala compiler can also deduce type parameters when polymorphic methods are called, or when generic classes are instantiated: case class InferedPair[A, B](a: A, b: B) val pairFirstInst = InferedPair("Husband", "Wife") //type is InferedPair[String, String] // Equiv...
There are scenarios in which Scala type-inference does not work. For instance, the compiler cannot infer the type of method parameters: def add(a, b) = a + b // Does not compile def add(a: Int, b: Int) = a + b // Compiles def add(a: Int, b: Int): Int = a + b // Equivalent expression, compiles ...
To split strings, Guava introduces the Splitter class. Why not use Java's splitting capabilities? As a rule, Guava does not duplicate functionality that is readily available in Java. Why then do we need an additional Splitter class? Do the split methods in Java's String class not provide us with a...
#include <SPI.h> #define CSPIN 1 void setup() { pinMode(CSPIN, OUTPUT); // init chip select pin as an output digitalWrite(CSPIN, 1); // most slaves interpret a high level on CS as "deasserted" SPI.begin(); SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MO...
#include <Servo.h> Servo srv; void setup() { srv.attach(9); // Attach to the servo on pin 9 } To use a servo, you need to call attach() function first. It starts generating a PWM signal controlling a servo on a specified pin. On boards other than Arduino Mega, use of Servo lib...
Returns the number of characters of the given String Considerations If a number is given instead a String, the result will be the length of the String representing the given number. I.e. If we execute length(12345) the result will be the same as length("12345"), that is 5 If...
To assign a value to a previously declared variable, use the assignment operator, =: a = 6; b = "Foo"; As an alternative to independent declaration and assignment, it is possible to perform both steps in one statement: var a = 6; let b = "Foo"; It is in this syntax that...
Here are some example on how to add new filters/functions to twig,the synax for adding Twig_Functions are the same as the Twig_Filter ones, just change the keywords accordingly <?php $twig = new Twig_Environment($loader); /* You can chain a global function */ $twig->addFilter(ne...
You can group all your custom functions/filters/tests/... inside a custom Twig_Extension class: ProjectTwigExtension class ProjectTwigExtension extends Twig_Extension { public function getFunctions() { return array( new Twig_SimpleFunction('twig_function_name', array($...
OneGet was originally a product from the Open Source Technology Center at Microsoft. Not only is it inspired by open-source Linux package managers, OneGet itself is also open source. It's now part of PowerShell As opposed to Unix based package managers (such as apt-get, yum, or dpkg), Windows allow...
Atomic variables can be accessed concurrently between different threads without creating race conditions. /* a global static variable that is visible by all threads */ static unsigned _Atomic active = ATOMIC_VAR_INIT(0); int myThread(void* a) { ++active; // increment active race fr...
Here is a workaround to temporary reset your password for your account. Login to your hosting panel and use the database tool that is available (probably PHPmyAdmin). Load the appropriate database and then go to the jos_users table. (The database prefix might be different for your case). ...
This is an example on how to call a web service from salesforce. The code below is calling a REST based service hosted on data.gov to find farmers markets close to the zipcode. Please remember in order to invoke a HTTP callout from your org, you need to tweak the remote settings for the org. strin...
Creation To create a Custom Setting, go to: Classic Setup > Develop > Custom Settings > New Lightning Setup > Custom Code > Custom Settings > New Create your setting (see the Remarks later in this document for the differences between Hierarchy & List custom settings). You...
Custom Setting Custom Setting Field Custom Setting Field Value When the field is checked the validation rule will be disabled, for the running user or in this example, their profile - The rule can also be disabled for a whole Salesforce org - Validation Rule AND( /* the below is the...
Explanation In this example a simple Trigger has been created to change the Close Date of an Opportunity, that's about to be inserted or updated, to a date 10 days in the future. The Apex Controller custom setting's checkbox field enables the code to be disabled at the user / profile / org level. ...
If you need to find the last day of the month, you can do complicated DateTime gymnastics or you can use the following method. Say you want to find the last day of February 2021. Do the following: Integer month = 2; Integer day = null; Integer year = 2021; // Create a new DateTime object for ...

Page 674 of 1336