Skip to content

Instantly share code, notes, and snippets.

View marinados's full-sized avatar
🤓

Marina Starkova marinados

🤓
  • Swile
  • Nantes
View GitHub Profile
  • Apache conf
  • Enable URL with OVH

Apache conf

cd /etc/apache2/sites-available

touch my-url.domaine.com.conf

Create mails with a new domain name

go to http://www.google.fr/intl/fr/enterprise/apps/business/products/gmail/

###Account Start it, fill fields...

###Check the domain Go to configuration, and valid the 2 first steps #####Step "google-site-verification" : On OVH, go to your domain, DNS area, add new entry. Choose TXT and set the value with google-site-verification=a_really_fat_string.

gid = class_instance.to_global_id # method allowing to get a string with both model name and id
GlobalID::Locator.locate(gid) # method of getting the object by its global id (very useful for collections of multiple type of objects, e.g. for polymorphic associations)
Example :
In the model that has a polymorphic attribute detailable:
getter:
def global_detailable
detailable.to_global_id if detailable.present?
@marinados
marinados / intro.py
Last active December 10, 2015 10:18
Pandas, Numpy, SciPy - libraries for vectorized calculations of non structured data
Folium - geographic data
iPython - work environment
List ~ Array (methods: append, insert, del)
Dictionary (dict) ~ Hash
.type ~ .class
| ~ ||
& ~ &&
config.time_zone #ActiveRecord fetches the UTC time from the database and converts it to the time zone in
DateTime #if you need support for times very far from the present
# Good practices
2.hours.ago # => Thu, 27 Aug 2015 14:39:36 AFT +04:30
1.day.from_now # => Fri, 28 Aug 2015 16:39:36 AFT +04:30
Time.zone.parse("2015-08-27T12:09:36Z") # => Thu, 27 Aug 2015 16:39:36 AFT +04:30
Time.current # => Thu, 27 Aug 2015 16:39:36 AFT +04:30
Time.current.utc.iso8601 # When supliyng an API ("2015-08-27T12:09:36Z")
# search(column name ('or' to be able to search in several columns + type de recherche, e.g. 'end' - last characters of the column, 'cont' - contains)
User.search('email_end' => 'gmail.com').result
User.search('first_name_or_last_name_cont' => 'bob').result
ActiveAdmin.describe User do
filter :first_name_cont, label: 'First Name'
end
# association name + name of column in the associated model + type of search
ActiveAdmin.describe User do
@marinados
marinados / some_useful_methods.rb
Created January 20, 2016 10:06
cool native ruby methods to use
# using bsearch wherenever possible :)
require 'benchmark'
data = (0..50_000_000)
Benchmark.bm do |x|
x.report(:find) { data.find {|number| number > 40_000_000 } }
x.report(:bsearch) { data.bsearch {|number| number > 40_000_000 } }
end
@marinados
marinados / slice.rb
Created February 3, 2016 13:37
slice method
a = ["a", "b", "c"]
a.slice(1, 2)
# => ["b", "c"]
a = ["a", "b", "c"]
a.slice_before("b").to_a
# => [["a"], ["b", "c"]]
a = ["000", "b", "999"]
a.slice_before(/[a-z]/).to_a
# to_i and to_int;
# to_s and to_str;
# to_a and to_ary;
# to_h and to_hash.
"string" + other #will call to_str on other, [1,2,3] + other will call #to_ary and so on (and will raise TypeError: no implicit conversion if object not responds to this methods);
"string" * other || [1,2,3] * other # will call #to_int on other;
a, b, c = *other # will call other to_ary (and, therefore, can be used to “unpack” custom collection objects—but also can cause unintended behavior, if other implements to_ary but was not thought as a collection);
some_method(*other) #—same as above, uses other#to_ary;
some_method(**other) #—new in Ruby 2, uses other#to_hash.
// child combinator (>)
ol > li {
color: red;
}
// general sibling combinator (~)
.featured-image ~ p {
font-size: 90%;
}