Tutorial by Examples

Use following methods if you want to skip the validations. These methods will save the object to the database even if it is invalid. decrement! decrement_counter increment! increment_counter toggle! touch update_all update_attribute update_column update_columns update_counters You ca...
class Person < ApplicationRecord validates :name, length: { minimum: 2 } validates :bio, length: { maximum: 500 } validates :password, length: { in: 6..20 } validates :registration_number, length: { is: 6 } end The possible length constraint options are: :minimum - The attribut...
The special attribute __name__ of a function, class or module is a string containing its name. import os class C: pass def f(x): x += 2 return x print(f) # <function f at 0x029976B0> print(f.__name__) # f print(C) # <class '__main__.C'> print(C.__name__...
Unlike Big-O notation, which represents only upper bound of the running time for some algorithm, Big-Theta is a tight bound; both upper and lower bound. Tight bound is more precise, but also more difficult to compute. The Big-Theta notation is symmetric: f(x) = Ө(g(x)) <=> g(x) = Ө(f(x)) An ...
Overload resolution occurs after name lookup. This means that a better-matching function will not be selected by overload resolution if it loses name lookup: void f(int x); struct S { void f(double x); void g() { f(42); } // calls S::f because global f is not visible here, ...
While it might seem counterintuitive, you can use logical operators to determine whether or not a statement is run. For instance: File.exist?(filename) or STDERR.puts "#{filename} does not exist!" This will check to see if the file exists and only print the error message if it doesn't....
You can create parser error messages according to your script needs. This is through the argparse.ArgumentParser.error function. The below example shows the script printing a usage and an error message to stderr when --foo is given but not --bar. import argparse parser = argparse.ArgumentParser...
First: The path structure If you don't have it you need to create the middleware folder within your app following the structure: yourproject/yourapp/middleware The folder middleware should be placed in the same folder as settings.py, urls, templates... Important: Don't forget to create the ini...
Boolean logic expressions, in addition to evaluating to True or False, return the value that was interpreted as True or False. It is Pythonic way to represent logic that might otherwise require an if-else test. And operator The and operator evaluates all expressions and returns the last expressi...
When you extend a class, you can override methods that the inherited class defines using the override keyword: public class Example { public function test():void { trace('It works!'); } } public class AnotherExample extends Example { public override function test():void ...
Say we have the following tree: root - A - AA - AB - B - BA - BB - BBA Now, if we wish to list all the names of the elements, we could do this with a simple for-loop. We assume there is a function get_name() to return a string of the name of a node, a function get_children() t...
If you have your data stored in a list and you want to convert this list to a data frame the do.call function is an easy way to achieve this. However, it is important that all list elements have the same length in order to prevent unintended recycling of values. dataList <- list(1:3,4:6,7:9) ...
class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] def index @posts = Post.all end def show end def new @post = Post.new end def edit end def create @post = Post.new(post_par...
Number of unique elements in a series: In [1]: id_numbers = pd.Series([111, 112, 112, 114, 115, 118, 114, 118, 112]) In [2]: id_numbers.nunique() Out[2]: 5 Get unique elements in a series: In [3]: id_numbers.unique() Out[3]: array([111, 112, 114, 115, 118], dtype=int64) In [4]: df = pd.Da...
Detailed instructions on getting tomcat set up or installed.
SAS can be run in client-server model, using either the Enterprise Guide thick client or the SAS Studio thin (web-enabled) client, or in "local server" mode where a fully functional SAS system is present on a local machine (Windows or Unix/Linux desktop or server running in interactive mod...
HTML5 provides a new standard for embedding an audio file on a web page. You can embed an audio file to a page using the <audio> element: <audio controls> <source src="file.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audi...
You can embed also a video to a webpage using the <video> element: <video width="500" height="700" controls> <source src="video.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
You can create your ssh key using ssh-keygen, it's a program that is part of the ssh installation. To do so just run it and follow the instructions on screen. Here's an example: $ ssh-keygen Generating public/private rsa key pair. The default directory where you ssh key pair will be saved is i...
Ever wanted to call a multicast delegate but you want the entire invokation list to be called even if an exception occurs in any in the chain. Then you are in luck, I have created an extension method that does just that, throwing an AggregateException only after execution of the entire list complete...

Page 260 of 1336