This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def kpi(campaigns) | |
{ | |
unique_views: campaigns.sum(:unique_views), | |
clicks: campaigns.sum(:clicker), | |
sent: campaigns.sum(:sent), | |
turnover: campaigns.sum(:turnover), | |
cost: campaigns.sum(:cost), | |
margin: campaigns.sum(:margin), | |
active_sent: active_campaigns.sum(:sent), | |
active_margin: active_campaigns.sum(:margin), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Usage: | |
rails generate test_unit:helper NAME [options] | |
Options: | |
[--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated applications) | |
Runtime options: | |
-f, [--force] # Overwrite files that already exist | |
-p, [--pretend], [--no-pretend] # Run but do not make any changes | |
-q, [--quiet], [--no-quiet] # Suppress status output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Scrabble do | |
def score(l) when l in [nil, ""] do: 0 | |
def score(l) when l in ["A", "E", "I", "O", "U"] do: 1 | |
def score(word) do | |
word | |
|> String.upcase | |
|> String.split("") | |
|> Enum.map(&(score(&1))) | |
|> Enum.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def if_statement | |
return a unless condition? | |
c( | |
1, | |
2, | |
3 | |
) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def if_statement | |
a | |
if condition? | |
c( | |
1, | |
2, | |
3 | |
) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent < ActiveRecord::Base | |
has_many :children | |
#Question: Does method below perform a join in children and match only children belonging to a specific parent? | |
def has_active_children | |
children.exists?(status: "active") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fetchs campaigns from SiB | |
class CampaignFetch | |
def get | |
def sib | |
@sib ||= Mailin.new("API_URL","API_KEY") | |
end | |
def shoot_criteria | |
{ "type"=>"classic", "status" => "sent", "page"=>10,"page_limit"=>1000 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fetchs SIB Account information | |
def sib_account_fetch | |
sib = Mailin.new("API_URL","API_KEY") | |
acct = sib.get_account() | |
acct.dig('data') | |
credits = acct.dig('data', 0).to_h | |
SibAccount.find(1).update_attributes(credits) | |
details = acct.dig('data', 2).to_h | |
SibAccount.find(1).update_attributes(details).delay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
page = Nokogiri::HTML(open("http://v-tac.eu/led-lights/lights1/led-spotlights/led-spotlight-7w-gu10-smd-white-plastic-white-detail.html")) | |
puts page.class # => Nokogiri::HTML::Document | |
fields = page.css(".product-field-type-S") | |
fields.each do |field| | |
key = field.css(".product-fields-title").text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_many :groups | |
end | |
class Group < ActiveRecord::Base | |
has_and_belongs_to_many :users | |
end |