Tutorial by Examples: c

Type switches can also be used to get a variable that matches the type of the case: func convint(v interface{}) (int,error) { switch u := v.(type) { case int: return u, nil case float64: return int(u), nil case string: return strconv(u) default: ...
Using Angular markup like {{hash}} in a src attribute doesn't work right. The browser will fetch from the URL with the literal text {{hash}} until Angular replaces the expression inside {{hash}}. ng-src directive overrides the original src attribute for the image tag element and solves the problem ...
By default, some keystrokes that are useful in Vim contradict with the keystrokes of IntelliJ. For example, ^R in Vim is 'redo', but in IntelliJ it's the shortcut for Run To decide which program interprets the keystroke, go to Preferences -> Other Settings -> Vim Emulation and choose which k...
RecyclerView will perform a relevant animation if any of the "notify" methods are used except for notifyDataSetChanged; this includes notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRemoved, etc. The adapter should extend this class instead of RecyclerView.Adapter. impo...
public class CustomTextView extends TextView { private float strokeWidth; private Integer strokeColor; private Paint.Join strokeJoin; private float strokeMiter; public CustomTextView(Context context) { super(context); init(null); } public ...
XAML controls may have dependency properties that can be bound to objects from DataContext or other controls. When the type of the object being bound is different from the type of the target DependencyProperty, a converter may be used to adapt one type to another. Converters are classes implementin...
SELECT Id, Name FROM Account This will return the Id and Name fields from the Account table. No filtering or sorting will be applied.
It is a common operation to need to perform a particular function over each element in a parameter pack. With C++11, the best we can do is: template <class... Ts> void print_all(std::ostream& os, Ts const&... args) { using expander = int[]; (void)expander{0, (void(...
Another way to implement item click listener is to use interface with several methods, the number of which is equal to the number of clickable views, and use overrided click listeners as you can see below. This method is more flexible, because you can set click listeners to different views and quite...
HVFL is a language designed to constrain UI elements in a simple and quick fashion. Generally, VFL has an advantage over traditional UI customization in the Interface Builder because it's much more readable, accessible and compact. Here's an example of VFL, in which three UIViews are constrained f...
A lot of the value from local JVM unit tests comes from the way you design your application. You have to design it in such a way where you can decouple your business logic from your Android Components. Here is an example of such a way using the Model-View-Presenter pattern. Lets practice this out by...
Property scrollEnabled stores a Boolean value that determines whether scrolling is enabled or not. If the value of this property is true/YES, scrolling is enabled, otherwise not.The default value is true Swift scrollview.isScrollEnabled = true Objective-C scrollview.scrollEnabled = YES;
Redirect to within application (another action of specific controller). return $this->redirect([ 'controller' => 'myController', 'action' => 'myAction' ]); Redirect to referrer page return $this->redirect($this->referer()); Redirect to outside of application or spec...
Passing Variable in URL as a method's parameter return $this->redirect([ 'controller' => 'users', 'action' => 'profile', $id ]); Url should be looks like this http://your_app_url/users/profile/{id} in UsersController.php file in profile() method class UsersController e...
Set default layout for entire application. i.e, created layout file in /src/Template/Layout/admin.ctp class AppsController extends Controller { public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->viewBuilder()->layout('admin'); // For Ver...
We can load components in two ways. By initialize or override $components property in Controller By using loadComponent() method in initialize() method of Controller. Way-1 It should be override loading component by AppsController.php load one or more component class UsersController extend...
dependencies { compile 'com.google.code.gson:gson:2.8.1' } To use latest version of Gson The below line will compile latest version of gson library everytime you compile, you do not have to change version. Pros: You can use latest features, speed and less bugs. Cons: It might break com...
Sometimes you need to serialize or deserialize some fields in a desired format, for example your backend may use the format "YYYY-MM-dd HH:mm" for dates and you want your POJOS to use the DateTime class in Joda Time. In order to automatically convert these strings into DateTimes object, y...
It's possible to compare lists and other sequences lexicographically using comparison operators. Both operands must be of the same type. [1, 10, 100] < [2, 10, 100] # True, because 1 < 2 [1, 10, 100] < [1, 10, 100] # False, because the lists are equal [1, 10, 100] <= [1, 10, 100] #...
To enable or disable a BroadcastReceiver, we need to get a reference to the PackageManager and we need a ComponentName object containing the class of the receiver we want to enable/disable: ComponentName componentName = new ComponentName(context, MyBroadcastReceiver.class); PackageManager packageM...

Page 354 of 826