Tutorial by Examples: cas

Suppose you have types like the following: interface IThing { } class Thing : IThing { } LINQ allows you to create a projection that changes the compile-time generic type of an IEnumerable<> via the Enumerable.Cast<>() and Enumerable.OfType<>() extension methods. IEnumerabl...
Here is an example Picasso Circle Transform class based on the original, with the addition of a thin border, and also includes functionality for an optional separator for stacking: import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import androi...
Type casting is done with either the as operator: var chair:Chair = furniture as Chair; Or by wrapping the value in Type(): var chair:Chair = Chair(furniture); If the cast fails with as, the result of that cast is null. If the cast fails by wrapping in Type(), a TypeError is thrown.
This function casts a ray from point origin in direction direction of length maxDistance against all colliders in the scene. The function takes in the origin direction maxDistance and calculate if there is a collider in front of the GameObject. Physics.Raycast(origin, direction, maxDistance); F...
If you need to search an ActiveRecord model for similar values, you might be tempted to use LIKE or ILIKE but this isn't portable between database engines. Similarly, resorting to always downcasing or upcasing can create performance issues. You can use ActiveRecord's underlying Arel matches method...
Picasso.with(context) .load(uri) .networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE) .placeholder(R.drawable.placeholder) .into(imageView);
Arithmetic operations are performed elementwise on Numpy arrays. For arrays of identical shape, this means that the operation is executed between elements at corresponding indices. # Create two arrays of the same size a = np.arange(6).reshape(2, 3) b = np.ones(6).reshape(2, 3) a # array([0, 1...
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...
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" ...
You can use raycasts to check if an ai can walk without falling off the edge of a level. using UnityEngine; public class Physics2dRaycast: MonoBehaviour { public LayerMask LineOfSightMask; void FixedUpdate() { RaycastHit2D hit = Physics2D.Raycas...
Mongoid allows the classic ActiveRecord associations: One-to-one: has_one / belongs_to One-to-many: has_many / belongs_to Many-to-many: has_and_belongs_to_many To add an association (lets say the User has_many posts), you can add this to your User model file: has_many :posts and this to ...
A variable can be downcasted to a subtype using the type cast operators as?, and as!. The as? operator attempts to cast to a subtype. It can fail, therefore it returns an optional. let value: Any = "John" let name = value as? String print(name) // prints Optional("John") ...
The switch statement can also be used to attempt casting into different types: func checkType(_ value: Any) -> String { switch value { // The `is` operator can be used to check a type case is Double: return "value is a Double" // The `as` operator will ...
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...
(Copy an item and send the copies to every block that it’s linked to) Unlike BufferBlock, BroadcastBlock’s mission in life is to enable all targets linked from the block to get a copy of every element published, continually overwriting the “current” value with those propagated to it. Additionally,...
It's possible to send broadcast to BroadcastReceiver with adb. In this example we are sending broadcast with action com.test.app.ACTION and string extra in bundle 'foo'='bar': adb shell am broadcast -a action com.test.app.ACTION --es foo "bar" You can put any other supported type to b...
Having your scripts call Raycast directly may lead to problems if you need to change the collision matrices in the future, as you'll have to track down every LayerMask field to accommodate the changes. Depending on the size of your project, this may become a huge undertaking. Encapsulating Raycast ...
We can use 1,2,3.. to determine the type of order: SELECT * FROM DEPT ORDER BY CASE DEPARTMENT WHEN 'MARKETING' THEN 1 WHEN 'SALES' THEN 2 WHEN 'RESEARCH' THEN 3 WHEN 'INNOVATION' THEN 4 ELSE 5 END, CITY IDREGIONCITYDEPARTMENTEMPLOYEES_N...
When results need to have some logic applied 'on the fly' one can use CASE statement to implement it. SELECT CASE WHEN Col1 < 50 THEN 'under' ELSE 'over' END threshold FROM TableName also can be chained SELECT CASE WHEN Col1 < 50 THEN 'under' WHEN Col1 > 50 AND Col1 ...

Page 5 of 14