Tutorial by Examples: c

ANTLR is distributed as a Java Jar file It can be downloaded here. As ANTLR is compiled as a jar file it subsequently requires the Java runtime environment to operate, if you do not have It can be downloaded here. Once the ANTLR JAR file has been downloaded you can run ANTLR from the command line i...
If your application is available in different languages, you usually show the current locale in the URL. scope '/(:locale)', locale: /#{I18n.available_locales.join('|')}/ do root 'example#root' # other routes end Your root will be accessible via the locales defined in I18n.available_l...
A self reference can be useful to build a hierarchical tree. This can be achieved with add_reference in a migration. class AddParentPages < ActiveRecord::Migration[5.0] def change add_reference :pages, :pages end end The foreign key column will be pages_id. If you want to decide a...
Gradle has the ability to add a wrapper to projects. This wrapper alleviates the need for all users or continuous integration systems to have Gradle installed. It also prevents version issues where there is some incompatibility between the version the project uses and that which users have installed...
Create SharedPreferences BuyyaPref SharedPreferences pref = getApplicationContext().getSharedPreferences("BuyyaPref", MODE_PRIVATE); Editor editor = pref.edit(); Storing data as KEY/VALUE pair editor.putBoolean("key_name1", true); // Saving boolean - true/false ...
Let's say you have class with generic methods. And you need to call its functions with reflection. public class Sample { public void GenericMethod<T>() { // ... } public static void StaticMethod<T>() { //... } } Let's say we want to...
From Apple documentation: Use the CTCallCenter class to obtain a list of current cellular calls, and to respond to state changes for calls such as from a dialing state to a connected state. Such state changes are known as cellular call events. The purpose of CTCallCenter is to give the develop...
You can subclass SKSpriteNode and define your own type of sprite. class Hero: SKSpriteNode { //Use a convenience init when you want to hard code values convenience init() { let texture = SKTexture(imageNamed: "Hero") self.init(texture: texture, color: .clearCol...
In contrast to segue that lets you pass data "forward" from current view controller to destination view controller: (VC1) -> (VC2) Using "unwind" you can do the opposite, pass data from the destination or current view controller to its presenting view controller: (VC1) <...
There are cases, where custom objects need to be created and defined in the resources of the application. Such objects can be composed of Java simple types, for example Integer, Float, String. Here is the example of how to import an object defined in application resources. The object Category cons...
Let's say you have a User model class User < ActiveRecord::Base end Now to update the first_name and last_name of a user with id = 1, you can write the following code. user = User.find(1) user.update(first_name: 'Kashif', last_name: 'Liaqat') Calling update will attempt to update the gi...
RoboGuice is a framework that brings the simplicity and ease of Dependency Injection to Android, using Google's own Guice library. RoboGuice 3 slims down your application code. Less code means fewer opportunities for bugs. It also makes your code easier to follow -- no longer is your code littered ...
It's possible to break / continue to an outer loop by using label statements: outerloop: for(...) { innerloop: for(...) { if(condition1) break outerloop; if(condition2) continue innerloop; // equivalent to: continue; } } There is no ...
The continue statement is used to skip the remaining steps in the current iteration and start with the next loop iteration. The control goes from the continue statement to the step value (increment or decrement), if any. String[] programmers = {"Adrian", "Paul", "John&quot...
public static void Main(string[] args) { var studentList = new List<Student>(); studentList.Add(new Student("Scott", "Nuke")); studentList.Add(new Student("Vincent", "King")); studentList.Add(new Student("Craig", "Be...
If you want the Value Types vs Reference Types in methods example to work properly, use the ref keyword in your method signature for the parameter you want to pass by reference, as well as when you call the method. public static void Main(string[] args) { ... DoubleNumber(ref number); ...
User is an ActiveRecord or Mongoid class. Replace User with any Rails class in your project (even something like Integer or Array) my_string = "User" # Capitalized string # => 'User' my_constant = my_string.safe_constantize # => User my_constant.all.count # => 18 my...
This example will not work because the string passed in isn't recognized as a constant in the project. Even if you pass in "array", it won't work as it isn't capitalized. my_string = "not_a_constant" # => 'not_a_constant' my_string.safe_constantize # => nil my_s...
If you are given a JSON string : val str = """{ | "name" : "Jsony McJsonface", | "age" : 18, | "hobbies" : [ "Fishing", "Hunting", "Camping" ], | "pet" : { | ...
C-style bit-manipulation A bit can be cleared using the bitwise AND operator (&). // Bit x will be cleared number &= ~(1LL << x); Using std::bitset reset(x) or set(x,false) - clears the bit at position x. std::bitset<5> num(std::string("01100")); num.reset(2); ...

Page 239 of 826