Tutorial by Examples: def

As the name suggest user defined exceptions are created by users. If you want to create your own exception you have to: Declare the exception Raise it from your program Create suitable exception handler to catch him. Example I want to update all salaries of workers. But if there are no work...
We may forget to apply the Antiforgery attribute for each POST request so we should make it by default. This sample will make sure Antiforgery filter will always be applied to every POST request. Firstly create new AntiForgeryTokenFilter filter: //This will add ValidateAntiForgeryToken Attribute t...
Sometimes users from other regions than English-speaking have problems with encoding while for example programming a php project. It can be, that the server has another encoding then UTF-8, and if someone want to create a php project in UTF-8 on this server, his text might be shown incorrect. Examp...
A child theme is identified by WordPress when there is a directory (for example child-theme) inside /wp-content/themes/ with the following files: style.css This file must start with a comment template like this: /* Theme Name: Example Child Author: Me Author URI: https://example.com/ ...
Trigger speech to text translation private void startListening() { //Intent to listen to user vocal input and return result in same activity Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); //Use a language model based on free-form speech recognition. ...
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var foo = new ClassWithDependency(); foo.DoSomething(); var bar = new InjectedDependency(); foo.Dependency = bar; ...
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var dep = new DefaultDependency(); var foo = new ClassWithDependency(dep); foo.DoSomething(); var bar = new Injected...
The XML document to consider in this example - <a> <b>test-value</b> <d>fragment-d</d> <c-root> <d>fragment-d</d> <e>fragment-e</e> </c-root> </a> A fragment root is declared on <c-r...
So now, let us finish the gulpfile code , by defining a Default task. the default task is the one that runs, when you just say gulp on a command prompt under the root of your project. $.task('default', ['generateResponsiveImages'], function() { $.start('watchdog'); console.log('Starting In...
Represents the definition of a single approval process. Use this object to read the description of an approval process. The definition is read-only. We can not modify the record created in ProcessDefinition Object. But we can describe, query, search and retrieve the approval processes information. ...
Very often it happens to deal with models which have something like a published field. Such kind of fields are almost always used when retrieving objects, so that you will find yourself to write something like: my_news = News.objects.filter(published=True) too many times. You can use custom mana...
There are three modes of XAML bindings exists for either Binding and x:Bind: OneTime: Update happens only once, on initialization of the view during InitializeComponent() call. (ViewModel[sends data when initializing] -> View) OneWay: View is updated when ViewModel changes. But not in the rev...
You can also loop over a variable list. From vars: favorite_snacks: - hotdog - ice cream - chips and then the loop: - name: create directories for storing my snacks file: path=/etc/snacks/{{ item }} state=directory with_items: '{{ favorite_snacks }}' If you are using Ansible ...
It is possible to create more complex loops with dictionaries. From vars: packages: - present: tree - present: nmap - absent: apache2 then the loop: - name: manage packages package: name={{ item.value }} state={{ item.key }} with_items: '{{ packages }}' Or, if you don't like ...
#lang racket (define (sum-of-list l) (if (null? l) 0 (+ (car l) (sum-of-list (cdr l))))) (sum-of-list '(1 2 3 4 5)) ;; => 15
mongodump --db mydb --gzip --out "mydb.dump.$(date +%F_%R)" This command will dump a bson gzipped archive of your local mongod 'mydb' database to the 'mydb.dump.{timestamp}' directory
mongorestore --db mydb mydb.dump.2016-08-27_12:44/mydb --drop --gzip This command will first drop your current 'mydb' database and then restore your gzipped bson dump from the 'mydb mydb.dump.2016-08-27_12:44/mydb' archive dump file.
1.Download font-awesome from here. 2.Copy the font-awesome directory into your project. 3.In the of your html, reference the location to your font-awesome.min.css. <link rel="stylesheet" href="path/to/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet&quot...
This custom UserControl will appear as a regular combobox, but unlike the built-in ComboBox object, it can show the user a default string of text if they have not made a selection yet. In order to accomplish this, our UserControl will be made up of two Controls. Obviously we need an actual ComboBox...
With Ruby you can modify the structure of the program in execution time. One way to do it, is by defining methods dynamically using the method method_missing. Let's say that we want to be able to test if a number is greater than other number with the syntax 777.is_greater_than_123?. # open Numeric...

Page 18 of 27