Tutorial by Examples: bas

Summary This goal is to reorganize all of your scattered commits into more meaningful commits for easier code reviews. If there are too many layers of changes across too many files at once, it is harder to do a code review. If you can reorganize your chronologically created commits into topical com...
Generics are placeholders for types, allowing you to write flexible code that can be applied across multiple types. The advantage of using generics over Any is that they still allow the compiler to enforce strong type-safety. A generic placeholder is defined within angle brackets <>. Generic...
cURL is a tool for transferring data with URL syntax. It support HTTP, FTP, SCP and many others(curl >= 7.19.4). Remember, you need to install and enable the cURL extension to use it. // a little script check is the cURL extension loaded or not if(!extension_loaded("curl")) { die...
Suppose we have a list of teams, named like this: Team A, Team B, ..., Team Z. Then: Team [AB]: This will match either either Team A or Team B Team [^AB]: This will match any team except Team A or Team B We often need to match characters that "belong" together in some context or ano...
# For Python 2 compatibility. from __future__ import print_function import lxml.html import requests def main(): r = requests.get("https://httpbin.org") html_source = r.text root_element = lxml.html.fromstring(html_source) # Note root_element.xpath() gives a *...
class UsersController < ApplicationController def index respond_to do |format| format.html { render html: "Hello World" } end end end This is a basic controller, with the addition of the following route (in routes.rb): resources :users, only: [:index] Will...
class UsersController < ApplicationController def index respond_to do |format| format.html do render html: "Hello #{ user_params[:name] } user_params[:sentence]" end end end private def user_params if params[:name] == "john&quo...
The following query returns the database options and metadata: select * from sys.databases WHERE name = 'MyDatabaseName';
Each time WordPress loads the page, it will run main loop. The loop is the way to iterate over all elements related to the page you are currently on. Main loop will work on a global WP_Query object. The query has a globalized method have_posts(), that allows us to loop through all results. Finally...
State in React components is essential to manage and communicate data in your application. It is represented as a JavaScript object and has component level scope, it can be thought of as the private data of your component. In the example below we are defining some initial state in the constructor f...
DataFrame: import pandas as pd import numpy as np np.random.seed(5) df = pd.DataFrame(np.random.randint(100, size=(5, 5)), columns = list("ABCDE"), index = ["R" + str(i) for i in range(5)]) df Out[12]: A B C D E R0 99 78 61 16 73...
Group by one column Using the following DataFrame df = pd.DataFrame({'A': ['a', 'b', 'c', 'a', 'b', 'b'], 'B': [2, 8, 1, 4, 3, 8], 'C': [102, 98, 107, 104, 115, 87]}) df # Output: # A B C # 0 a 2 102 # 1 b 8 98 # 2 c 1 107 # 3 a...
SELECT s.name + '.' + t.NAME AS TableName, SUM(a.used_pages)*8 AS 'TableSizeKB' --a page in SQL Server is 8kb FROM sys.tables t JOIN sys.schemas s on t.schema_id = s.schema_id LEFT JOIN sys.indexes i ON t.OBJECT_ID = i.object_id LEFT JOIN sys.partitions p ON i.object_id = ...
XML elements often nest, have data in attributes and/or as character data. The way to capture this data is by using ,attr and ,chardata respectively for those cases. var doc = ` <parent> <child1 attr1="attribute one"/> <child2>and some cdata</child2> </p...
MediaPlayer class can be used to control playback of audio/video files and streams. Creation of MediaPlayer object can be of three types: Media from local resource MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.resource); mediaPlayer.start(); // no need to call prepare(); create...
import "reflect" value := reflect.ValueOf(4) // Interface returns an interface{}-typed value, which can be type-asserted value.Interface().(int) // 4 // Type gets the reflect.Type, which contains runtime type information about // this value value.Type().Name() // int value.SetInt(5)...
Custom filters in Vue.js can be created easily in a single function call to Vue.filter. //JS Vue.filter('reverse', function(value) { return value.split('').reverse().join(''); }); //HTML <span>{{ msg | reverse }}</span> //'This is fun!' => '!nuf si sihT' It is good prac...
from pandas_datareader import data # Only get the adjusted close. aapl = data.DataReader("AAPL", start='2015-1-1', end='2015-12-31', data_source='yahoo')['Adj Close'] >>> aapl.plot(title='AAPL Adj. C...
This method will work on modern versions of Arch, CentOS, CoreOS, Debian, Fedora, Mageia, openSUSE, Red Hat Enterprise Linux, SUSE Linux Enterprise Server, Ubuntu, and others. This wide applicability makes it an ideal as a first approach, with fallback to other methods if you need to also identify o...
While Value Converters can be comprised of either a toView or fromView method, in the below example we will be creating a basic Value Converter which just uses the toView method which accepts the value being sent to the view as the first argument. to-uppercase.js export class ToUppercaseValueConve...

Page 12 of 65