Tutorial by Examples

You can get a Model class from a Controller name this way (context is Controller class): class MyModelController < ActionController::Base # Returns corresponding model class for this controller # @return [ActiveRecord::Base] def corresponding_model_class # ... add some validation...
In the case of a multi-project gradle build, you may sometimes need to depend on another project in your build. To accomplish this, you'd enter the following in your project's dependencies: dependencies { compile project(':OtherProject') } Where ':OtherProject' is the gradle path for the p...
Testing your Active Record models through your command line interface is simple. Navigate to the app directory in your terminal and type in rails console to start the Rails console. From here, you can run active record methods on your database. For example, if you had a database schema with a User...
Consumable Managed Products are products that can be bought multiple times such as in-game currency, game lives, power-ups, etc. In this example, we are going to implement 4 different consumable managed products "item1", "item2", "item3", "item4". Steps in...
DISCLAIMER: Scaffolding is not recommended unless it's for very conventional CRUD apps/testing. This may generate a lot of files(views/models/controllers) that are not needed in your web application thus causing headaches(bad :(). To generate a fully working scaffold for a new object, including mod...
console.count([obj]) places a counter on the object's value provided as argument. Each time this method is invoked, the counter is increased (with the exception of the empty string ''). A label together with a number is displayed in the debugging console according to the following format: [label]: ...
Debug.log's second argument is always returned, so you could write code like the following and it would just work: update : Msg -> Model -> (Model, Cmd Msg) update msg model = case Debug.log "The Message" msg of Something -> ... Replacing case msg o...
{{1,2}, {3,4}} leads to: TypeError: unhashable type: 'set' Instead, use frozenset: {frozenset({1, 2}), frozenset({3, 4})}
Any lodash collection method has two syntaxes. Without chaining: var arr1 = [10, 15, 20, 25, 30, 15, 25, 35]; var arr2 = _.filter(arr1, function(item){ return item % 10 === 5 }); // arr2 now contains [15, 25, 15, 25, 35] var arr3 = _.uniq(arr2); // arr3 now contains [15, 25, 35] var arr...
There are a few libraries for unit testing in Common Lisp FiveAM Prove, with a few unique features like extensive test reporters, colored output, report of test duration and asdf integration. Lisp-Unit2, similar to JUnit Fiasco, focusing on providing a good testing experience from the REPL. Su...
The Java language provides 4 operators that perform bitwise or logical operations on integer or boolean operands. The complement (~) operator is a unary operator that performs a bitwise or logical inversion of the bits of one operand; see JLS 15.15.5.. The AND (&) operator is a binary operat...
By default, all the .panel does is apply some basic border and padding to contain some content. <div class="panel panel-default"> <div class="panel-body"> Basic panel example </div> </div>
Easily add a heading container to your panel with .panel-heading. You may also include any <h1>-<h6> with a .panel-title class to add a pre-styled heading. However, the font sizes of <h1>-<h6> are overridden by .panel-heading. For proper link coloring, be sure to place links...
Wrap buttons or secondary text in .panel-footer. Note that panel footers do not inherit colors and borders when using contextual variations as they are not meant to be in the foreground. <div class="panel panel-default"> <div class="panel-body"> Panel content...
The following example can be tested on https://ellie-app.com/m9tk39VpQg/0. import Html exposing (..) import Json.Decode payload = """ ["fu", "bar"] """ main = Json.Decode.decodeString decoder payload -- Ok ["fu","b...
The following examples can be tested on https://ellie-app.com/m9vmQ8NcMc/0. import Html exposing (..) import Json.Decode payload = """ [ { "bark": true, "tag": "dog", "name": "Zap", "playful": true } , { "w...
Content scripts can be declared in manifest.json to be always injected into pages that match a set of URL patterns. Minimal example "content_scripts" : [ { "js": ["content.js"], "css": ["content.css"] "matches": [&quot...
If, instead of always having a content script injected based on the URL, you want to directly control when a content script is injected, you can use Programmatic Injection. Minimal example JavaScript chrome.tabs.executeScript({file: "content.js"}); CSS chrome.tabs.insert...
Same conditions, multiple scripts If you need to inject multiple files with all other conditions being the same, for example to include a library, you can list all of them in the "js" array: "content_scripts" : [ { "js": ["library.js", "conten...
There are two basic styles of type conversion in Go: // Simple type conversion var x := Foo{} // x is of type Foo var y := (Bar)Foo // y is of type Bar, unless Foo cannot be cast to Bar, then compile-time error occurs. // Extended type conversion var z,ok := x.(Bar) // z is of type Bar, o...

Page 367 of 1336