Tutorial by Examples: c

Provided an App.GoogleMap coffee script class and the marker information being stored in the data-address-fields attribute of the .google_map div, the map markers can be initialized on the map like this: # app/assets/javascripts/google_maps.js.coffee # ... class App.GoogleMap # ... markers:...
Provided an App.GoogleMap coffee script class with the google.maps.Map stored as @map and the google.maps.Markers stored as @markers, the map can be auto-zoomed, i.e. adjusted that all markers are visible, like this: on the map like this: # app/assets/javascripts/google_maps.js.coffee # ... cla...
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...
NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.some_small_icon) .setContentTitle("Title") .setContentText("This is a test notification with MAX priority")...
A has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model. For example, consider a medical practice where p...
A has_one :through association sets up a one-to-one connection with another model. This association indicates that the declaring model can be matched with one instance of another model by proceeding through a third model. For example, if each supplier has one account, and each account is associated...
A has_and_belongs_to_many association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models...
Picasso.with(context) .load(uri) .networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE) .placeholder(R.drawable.placeholder) .into(imageView);
Sometimes it can be useful to set your application locale based upon the request IP. You can easily achieve this using Geocoder. Among the many things Geocoder does, it can also tell the location of a request. First, add Geocoder to your Gemfile # Gemfile gem 'geocoder' Geocoder adds location...
We can check the status of migrations by running 3.05.0 rake db:migrate:status 5.0 rails db:migrate:status The output will look like this: Status Migration ID Migration Name -------------------------------------------------- up 20140711185212 Create documentation pages up ...
Rails have very easy way to get first and last record from database. To get the first record from users table we need to type following command: User.first It will generate following sql query: SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1 And will return following recor...
An easy way to clone an object is by implementing a copy constructor. public class Sheep { private String name; private int weight; public Sheep(String name, int weight) { this.name = name; this.weight = weight; } // copy constructor // copies...
Cloning an object by implementing the Cloneable interface. public class Sheep implements Cloneable { private String name; private int weight; public Sheep(String name, int weight) { this.name = name; this.weight = weight; } @Override public Ob...
Start using File Uploads in Rails is quite simple, first thing you have to do is to choice plugin for managing uploads. The most common onces are Carrierwave and Paperclip. Both are similar in functionality and rich in documentation on Let's have an look on example with simple avatar upload image w...
Rails.cache, provided by ActiveSupport, can be used to cache any serializable Ruby object across requests. To fetch a value from the cache for a given key, use cache.read: Rails.cache.read('city') # => nil Use cache.write to write a value to the cache: Rails.cache.write('city', 'Duckburgh'...
You can use the ActionPack page_caching gem to cache individual pages. This stores the result of one dynamic request as a static HTML file, which is served in place of the dynamic request on subsequent requests. The README contains full setup instructions. Once set up, use the caches_page class meth...
Rails >= 3 comes with HTTP caching abilities out of the box. This uses the Cache-Control and ETag headers to control how long a client or intermediary (such as a CDN) can cache a page. In a controller action, use expires_in to set the length of caching for that action: def show @user = User....
“Fat Model, Skinny Controller” refers to how the M and C parts of MVC ideally work together. Namely, any non-response-related logic should go in the model, ideally in a nice, testable method. Meanwhile, the “skinny” controller is simply a nice interface between the view and model. In practice, this...
GCD will guarantee that your singleton only gets instantiated once, even if called from multiple threads. Insert this into any class for a singleton instance called shared. + (instancetype)shared { // Variable that will point to the singleton instance. The `static` // modifier makes it ...
Given a file file.txt with the following content: line 1 line 2 line 3 You can add a new line after first matching line with the a command. For portable use the a command must be followed immediately by an escaped newline, with the text-to-append on its own line or lines. sed ' /line 2/a\ ...

Page 223 of 826