add_index using: :btree

add_index "table_name", ["column_name"], name: "index_table_name_on_column_name", using: :btree

Generate

CREATE INDEX index_developers_on_name ON developers USING btree (name) -- PostgreSQL
CREATE INDEX index_developers_on_name USING btree ON developers (name) -- MySQL

Note: only supported by PostgreSQL and MySQL

The database stores the value indexed as a B-Tree key, and the record pointer as a B-Tree value.

In InnoDB, the record pointer is the value of the PRIMARY KEY.

 

Default mysql index is btree ? https://stackoverflow.com/questions/1687910/advantage-of-btree

ref : https://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/add_index,

https://stackoverflow.com/questions/2362667/how-b-tree-indexing-works-in-mysql

 

Advertisements

[ ruby ] def whatever_function=(param) : defines a setter ( Virtual Attributes / Uniform Access Principle )

Practical Example

You might want to access the duration in minutes and fractions of a minute, rather than in seconds as we’ve been doing.

class Song
def durationInMinutes
@duration/60.0 # force floating point
end
def durationInMinutes=(value)
@duration = (value*60).to_i
end
end
aSong = Song.new("Bicylops", "Fleck", 260)
aSong.durationInMinutes » 4.333333333
aSong.durationInMinutes = 4.2
aSong.duration » 252

Other Example 

class Foo
def foo=(x)
puts "OK: x=#{x}"
end
end
f = Foo.new
f.foo = 123 # => 123
# OK: x=123

Note also that such setter methods always return their argument.

top-level setter method

def bar=(y)
puts "OK: y=#{y}"
end
bar = 123 # => 123, sets the variable "bar".
bar # => 123
Object.new.bar = 123 # => 123, calls our method
# OK: y=123
Object.public_methods.grep /bar/ # => ["bar="]

Other ruby

has_full_name? : is expected to return a boolean value if the object has a full_name

revert_full_name! :

ref : http://ruby-doc.com/docs/ProgrammingRuby/html/tut_classes.html#UC,

https://stackoverflow.com/questions/25960406/what-does-def-function-param-mean-in-ruby,

https://stackoverflow.com/questions/5398919/what-does-the-equal-symbol-do-when-put-after-the-method-name-in-a-method-d,

 

GPT : Google Publisher Tag

insert gpt library

var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();

 

googletag.defineSlot

SYNTAX

googletag.defineSlot(adUnitPath, size, opt_div)

opt_div : ID of the div that will contain this ad unit.

USAGE

googletag.cmd.push(function() {

googletag.defineSlot('/1234567/sports', [728, 90], 'div-1').defineSizeMapping(googletag.sizeMapping().
addSize([1024, 768], [970, 250]).
addSize([980, 690], [728, 90]).
addSize([640, 480], [120, 60]).
addSize([0, 0], [88, 31]).
// Fits browsers of any size smaller than 640 x 480
build() ).addService(googletag.pubads());
googletag.pubads().enableSingleRequest(); // Enables single request mode for fetching multiple ads at the same time
googletag.enableServices(); // Enables all GPT services that have been defined for ad slots on the page
});

defineSizeMapping

First, call .sizeMapping to map the ad sizes to browser sizes and then call .defineSizeMapping to implement the mapping.

googletag.sizeMapping().addSize(browser size, ad sizes)

The first dimension you specify for addSize is the browser size and each subsequent dimension is an ad size.
For example, in the first addSize defined above, [1024, 768] is the browser size and [970, 250] is the ad size.

GPT will detect the browser size and use the largest mapping that fits.
To determine the largest mapping GPT will first consider width, then height (i.e. [100, 10] > [10, 100]).

browser size = [0, 0]

= a default mapping that can be used on any browser size

.defineSlot

If there is an error in the mapping or if the browser size can’t be determined, the sizes specified in .defineSlot will be used.

Good to know

The adslot.defineSizeMapping() method will receive an array of mappings in the following form:
[ [ [ 1024, 768 ], [ [ 970, 250 ] ] ],

[ [ 980, 600 ], [ [ 728, 90 ], [ 640, 480 ] ] ],

],

( [1024, 768] and [728, 90] = browser size; the rest = slot sizes )
which should be ordered from highest to lowest priority. The builder syntax is a more readable way of defining the mappings that orders them automatically.
However, you have the option of using different priority ordering by bypassing the builder and constructing the array of mappings manually.

ref : https://developers.google.com/doubleclick-gpt/reference ,

https://support.google.com/dfp_premium/answer/3423562?hl=en ,

https://support.google.com/dfp_premium/topic/28134?hl=en&ref_topic=4388125

 

refresh publish ads

googletag.pubads().refresh();

ref : https://support.google.com/dfp_premium/answer/2694377?hl=en

 

time to fetch creative

googletag.openConsole()

 

 

 

 

[ lodash ] _.filter match property

var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false }
];
<p style="text-align: left;">// The `_.property` iteratee shorthand.
_.filter(users, 'active');
// => objects for ['barney']

_.filter(users, function(o) { return !o.active; });
// => objects for ['fred']

ref : https://lodash.com/docs/4.17.4#filter

[ rails ] retrieving filtered data from multiple tables

x = Person .select('people.id, people.name, comments.text') .joins(:comments) .where('comments.created_at &gt; ?', 1.week.ago)

x will be a #Person object

The result should be something like this:

SELECT people.id, people.name, comments.text
FROM people
INNER JOIN comments
 ON comments.person_id = people.id
WHERE comments.created_at &gt; '2015-01-01'

ref : http://guides.rubyonrails.org/active_record_querying.html