Tutorial by Examples: ase

To add a value to a Set, use the .add() method: mySet.add(5); If the value already exist in the set it will not be added again, as Sets contain unique values. Note that the .add() method returns the set itself, so you can chain add calls together: mySet.add(1).add(2).add(3);
To remove a value from a set, use .delete() method: mySet.delete(some_val); This function will return true if the value existed in the set and was removed, or false otherwise.
To check if a given value exists in a set, use .has() method: mySet.has(someVal); Will return true if someVal appears in the set, false otherwise.
It is also possible to use Scala's string interpolation feature to create elaborate extractors (pattern matchers), as perhaps most famously employed in the quasiquotes API of Scala macros. Given that n"p0${i0}p1" desugars to new StringContext("p0", "p1").n(i0), it is p...
Comparing string in a case insensitive way seems like something that's trivial, but it's not. This section only considers unicode strings (the default in Python 3). Note that Python 2 may have subtle weaknesses relative to Python 3 - the later's unicode handling is much more complete. The first thi...
Logistic regression is a particular case of the generalized linear model, used to model dichotomous outcomes (probit and complementary log-log models are closely related). The name comes from the link function used, the logit or log-odds function. The inverse function of the logit is called the lo...
You can remove all the elements in a set using the .clear() method: mySet.clear();
To filter a selection you can use the .filter() method. The method is called on a selection and returns a new selection. If the filter matches an element then it is added to the returned selection, otherwise it is ignored. If no element is matched then an empty selection is returned. The HTML Thi...
base.twig.html <!DOCTYPE html> <html> <head> <title>{{ title | default('Hello World') }}</title> <link rel="stylesheet" type="text/css" href="theme.css"> {% block css %} {% endblock %} &...
Rails is shipped by default with ActiveRecord, an ORM (Object Relational Mapping) derived from the pattern with the same name. As an ORM, it is built to handle relational-mapping, and more precisely by handling SQL requests for you, hence the limitation to SQL databases only. However, you can stil...
With the case statement you can match values against one variable. The argument passed to case is expanded and try to match against each patterns. If a match is found, the commands upto ;; are executed. case "$BASH_VERSION" in [34]*) echo {1..4} ;; *) seq -s" ...
Suppose we want to count how many counties are there in Texas: var counties = dbContext.States.Single(s => s.Code == "tx").Counties.Count(); The query is correct, but inefficient. States.Single(…) loads a state from the database. Next, Counties loads all 254 counties with all of the...
select_dtypes method can be used to select columns based on dtype. In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': ['a', 'b', 'c'], 'D': [True, False, True]}) In [2]: df Out[2]: A B C D 0 1 1.0 a True 1 2 2.0 b False 2...
In PaaS sites such as Heroku, it is usual to receive the database information as a single URL environment variable, instead of several parameters (host, port, user, password...). There is a module, dj_database_url which automatically extracts the DATABASE_URL environment variable to a Python dictio...
Useful for scripting to drop all tables and deletes the database: mysqladmin -u[username] -p[password] drop [database] Use with extreme caution. To DROP database as a SQL Script (you will need DROP privilege on that database): DROP DATABASE database_name or DROP SCHEMA database_name
A self reference can be useful to build a hierarchical tree. This can be achieved with add_reference in a migration. class AddParentPages < ActiveRecord::Migration[5.0] def change add_reference :pages, :pages end end The foreign key column will be pages_id. If you want to decide a...
Mongoid tries to have similar syntax to ActiveRecord when it can. It supports these calls (and many more) User.first #Gets first user from the database User.count #Gets the count of all users from the database User.find(params[:id]) #Returns the user with the id found in params[:id] User.w...
A pointer to base class can be converted to a pointer to derived class using static_cast. static_cast does not do any run-time checking and can lead to undefined behaviour when the pointer does not actually point to the desired type. struct Base {}; struct Derived : Base {}; Derived d; Base* p1 ...
XML <Galaxy> <Light>sun</Light> <Device>satellite</Device> <Sensor>human</Sensor> <Name>Milky Way</Name> </Galaxy> XPATH /Galaxy/*[lower-case(local-name())="light"] or //*[lower-case(local-name())=&qu...
XML <Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy> XPATH /Galaxy/*[contains(lower-case(@name),'ear')] or //*[contain...

Page 10 of 40