Skip to content

Instantly share code, notes, and snippets.

View novikserg's full-sized avatar

Sergei Novik novikserg

  • Amsterdam
View GitHub Profile
class CreatePost
def self.call(*args)
new(*args).call
end
include Virtus.model
attribute :user
attribute :post_params
attribute :image
class GetFacebookPages
def self.call(*args)
new(*args).call
end
include Virtus.model
attribute :account, FacebookAccount
def call
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
xlsx = Roo::Spreadsheet.open('db/xlsx/zipcodes.xlsx')
sheet = xlsx.sheet(0)
class FacebookGraph
def initialize(token)
@graph = Koala::Facebook::API.new(token)
end
def profile
@graph.get_object('me')
end
def friends_ids
class MyClass
def word
"word"
end
def go
word = word
word
end
end
class MyClass
def word
"word"
end
def go
word = word + "whatever"
word
end
end
# full description:
# https://codility.com/demo/take-sample-test/ps/
# tl;dr: Write a function that, given a zero-indexed non-empty array A consisting of N integers, returns the first covering prefix of A.
def solution(a)
last_unique = a.uniq.last
a.index { |el| el == last_unique }
end
class Triangle
attr_reader :a
attr_reader :b
attr_reader :c
def initialize(a, b, c)
@a, @b, @c = a, b, c
end
def type
class BuckFizz
def print
all.each do |buck_fizz|
puts buck_fizz
end
end
private
def all
@novikserg
novikserg / fibbonaci_iterate.exs
Last active February 21, 2018 07:21
A quick example of Fibbonaci sequence using Elixir's Stream (unlike eager Enums, Streams are lazy, generated 1 by 1 during execution, and highly composable)
def fibbonaci_iterate do
Stream.unfold([0, 1], fn [prev, curr] -> {curr, [curr, (prev + curr)]} end)
end
# fibbonaci_iterate |> Stream.take_every(10) |> Stream.map(fn(x) -> x * 2 end) |> Enum.take(5)
# [2, 178, 21892, 2692538, 331160282]
# note that the list was actually only enumerated once