Tutorial by Examples

You can use all() to determine if all the values in an iterable evaluate to True nums = [1, 1, 0, 1] all(nums) # False chars = ['a', 'b', 'c', 'd'] all(chars) # True Likewise, any() determines if one or more values in an iterable evaluate to True nums = [1, 1, 0, 1] any(nums) # True val...
Add this permission to the manifest file to use Bluetooth features in your application: <uses-permission android:name="android.permission.BLUETOOTH" /> If you need to initiate device discovery or manipulate Bluetooth settings, you also need to add this permission: <uses-permi...
private static final int REQUEST_ENABLE_BT = 1; // Unique request code BluetoothAdapter mBluetoothAdapter; // ... if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_B...
private static final int REQUEST_DISCOVERABLE_BT = 2; // Unique request code private static final int DISCOVERABLE_DURATION = 120; // Discoverable duration time in seconds // 0 means always discoverable ...
Declare a BluetoothAdapter first. BluetoothAdapter mBluetoothAdapter; Now create a BroadcastReceiver for ACTION_FOUND private final BroadcastReceiver mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); //...
A list of recognised color keyword names can be found in the W3C Recommendation for SVG. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <circle r="30" cx="100" cy="100" fill="red" stroke=&qu...
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <circle r="30" cx="100" cy="100" fill="#ff0000" stroke="#00ff00" /> <rect x="200" y="200" width="50&...
where can serve two purposes in C#: type constraining in a generic argument, and filtering LINQ queries. In a generic class, let's consider public class Cup<T> { // ... } T is called a type parameter. The class definition can impose constraints on the actual types that can be suppl...
Count returns the number of elements in an IEnumerable<T>. Count also exposes an optional predicate parameter that allows you to filter the elements you want to count. int[] array = { 1, 2, 3, 4, 2, 5, 3, 1, 2 }; int n = array.Count(); // returns the number of elements in the array int x ...
To search for a string inside a string, there are several functions: indexOf( searchString ) and lastIndexOf( searchString ) indexOf() will return the index of the first occurrence of searchString in the string. If searchString is not found, then -1 is returned. var string = "Hello, World!&q...
Sometimes it is useful to have multiple validations use one condition. It can be easily achieved using with_options. class User < ApplicationRecord with_options if: :is_admin? do |admin| admin.validates :password, length: { minimum: 10 } admin.validates :email, presence: true end...
This type of association allows an ActiveRecord model to belong to more than one kind of model record. Common example: class Human < ActiveRecord::Base has_one :address, :as => :addressable end class Company < ActiveRecord::Base has_one :address, :as => :addressable end cl...
The idea here is to move the computationally intensive jobs to C (using special macros), independent of Python, and have the C code release the GIL while it's working. #include "Python.h" ... PyObject *pyfunc(PyObject *self, PyObject *args) { ... Py_BEGIN_ALLOW_THREADS //...
Support vector machines is a family of algorithms attempting to pass a (possibly high-dimension) hyperplane between two labelled sets of points, such that the distance of the points from the plane is optimal in some sense. SVMs can be used for classification or regression (corresponding to sklearn.s...
A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and use averaging to improve the predictive accuracy and control over-fitting. A simple usage example: Import: from sklearn.ensemble import RandomForestClassifier Define tr...
git blame <file> will show the file with each line annotated with the commit that last modified it.
Sometimes repos will have commits that only adjust whitespace, for example fixing indentation or switching between tabs and spaces. This makes it difficult to find the commit where the code was actually written. git blame -w will ignore whitespace-only changes to find where the line really came fr...
Output can be restricted by specifying line ranges as git blame -L <start>,<end> Where <start> and <end> can be: line number git blame -L 10,30 /regex/ git blame -L /void main/, git blame -L 46,/void foo/ +offset, -offset (only for <end>) git blame -...
One of the uses of recursion is to navigate through a hierarchical data structure, like a file system directory tree, without knowing how many levels the tree has or the number of objects on each level. In this example, you will see how to use recursion on a directory tree to find all sub-directorie...
It is a good idea to maintain a web-scraping session to persist the cookies and other parameters. Additionally, it can result into a performance improvement because requests.Session reuses the underlying TCP connection to a host: import requests with requests.Session() as session: # all req...

Page 307 of 1336