Tutorial by Examples

Imagine you have the following HTML: <div> <label>Name:</label> John Smith </div> And you need to locate the text "John Smith" after the label element. In this case, you can locate the label element by text and then use .next_sibling property: from ...
BeautifulSoup has a limited support for CSS selectors, but covers most commonly used ones. Use select() method to find multiple elements and select_one() to find a single element. Basic example: from bs4 import BeautifulSoup data = """ <ul> <li class="item&quo...
Sets are unordered collections of distinct elements. But sometimes we want to work with unordered collections of elements that are not necessarily distinct and keep track of the elements' multiplicities. Consider this example: >>> setA = {'a','b','b','c'} >>> setA set(['a', 'c'...
You can restrict the valid types used in a generic class by bounding that type in the class definition. Given the following simple type hierarchy: public abstract class Animal { public abstract String getSound(); } public class Cat extends Animal { public String getSound() { ...
Sometimes it's necessary to be able to extract values from an object using only references (ie. without transferring ownership). struct Token { pub id: u32 } struct User { pub token: Option<Token> } fn main() { // Create a user with an arbitrary token let user = User...
Let's say we have the following data: >>> data = {"cats": [{"name": "Tubbs", "color": "white"}, {"name": "Pepper", "color": "black"}]} Just dumping this as JSON does not do anything special here: ...
Have a table NameAgeCityBob10ParisMat20BerlinMary24Prague select Name from table where Age>10 AND City='Prague' Gives NameMary select Name from table where Age=10 OR City='Prague' Gives NameBobMary
Light Table is a good editor to learn, experiment and run Clojure projects. You can also run lein/boot projects by opening project.clj file. It will load all project dependencies. It supports inline evalution, plugins and much more, so there's no need to add print statements and check the output i...
To setup Emacs for working with Clojure, install clojure-mode and cider package from melpa: M-x package-install [RET] clojure-mode [RET] M-x package-install [RET] cider [RET] Now when you open a .clj file, run M-x cider-jack-in to connect to a REPL. Alternatively, you can use C-u M-x (cider-jac...
All built-in Clojure collections are immutable and heterogeneous, have literal syntax, and support the conj, count, and seq functions. conj returns a new collection that is equivalent to an existing collection with an item "added", in either "constant" or logarithmic time. Wha...
A list is denoted by parentheses: () ;;=> () A Clojure list is a singly linked list. conj "conjoins" a new element to the collection in the most efficient location. For lists, this is at the beginning: (conj () :foo) ;;=> (:foo) (conj (conj () :bar) :foo) ;;=> (:foo :ba...
A sequence is very much like a list: it is an immutable object that can give you its first element or the rest of its elements in constant time. You can also construct a new sequence from an existing sequence and an item to stick at the beginning. You can test whether something is a sequence using ...
A vector is denoted by square brackets: [] ;;=> [] [:foo] ;;=> [:foo] [:foo :bar] ;;=> [:foo :bar] [1 (+ 1 1) 3] ;;=> [1 2 3] In addition using to the literal syntax, you can also use the vector function to construct a vector: (vector) ;;=> [] (vector :foo) ;;=&...
Like maps, sets are associative and unordered. Unlike maps, which contain mappings from keys to values, sets essentially map from keys to themselves. A set is denoted by curly braces preceded by an octothorpe: #{} ;;=> #{} #{:foo} ;;=> #{:foo} #{:foo :bar} ;;=> #{:bar :foo} As...
Unlike the list, which is a sequential data structure, and the vector, which is both sequential and associative, the map is exclusively an associative data structure. A map consists of a set of mappings from keys to values. All keys are unique, so maps support "constant"-time lookup from k...
For if you have to fine-tune what is published. import { Mongo } from 'meteor/mongo'; import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; if (Meteor.isClient) { // established this collection on the client only. // a name is required (first parameter) and this...
On the server, you can create a publication like this. this.userId is the id of the user who is currently logged in. If no user is logged in, you might want to throw an error and respond to it. import Secrets from '/imports/collections/Secrets'; Meteor.publish('protected_data', function () { ...
Swift 3 let stackView = UIStackView() stackView.axis = .horizontal stackView.alignment = .fill // .leading .firstBaseline .center .trailing .lastBaseline stackView.distribution = .fill // .fillEqually .fillProportionally .equalSpacing .equalCentering let label = UILabel() label.text = "...
Swift let stackView = UIStackView() stackView.axis = .Vertical stackView.alignment = .Fill // .Leading .FirstBaseline .Center .Trailing .LastBaseline stackView.distribution = .Fill // .FillEqually .FillProportionally .EqualSpacing .EqualCentering let label = UILabel(frame: CGRectZero) label....
You can take a snapshot from a UIView like this: Swift let snapshot = view.snapshotView(afterScreenUpdates: true) Objective-C UIView *snapshot = [view snapshotViewAfterScreenUpdates: YES];

Page 171 of 1336