Skip to content

Instantly share code, notes, and snippets.

View luctus's full-sized avatar
🤓

Gustavo Garcia luctus

🤓
View GitHub Profile
@luctus
luctus / keybase.md
Created June 22, 2022 11:41
keybase.md

Keybase proof

I hereby claim:

  • I am luctus on github.
  • I am theluctus (https://keybase.io/theluctus) on keybase.
  • I have a public key ASAOu0tadQXNk5a2f5k6r7t4L0S2O0RdtjfqcKhoBPwH3Qo

To claim this, I am signing this object:

@luctus
luctus / liam_producer.rb
Last active February 25, 2020 12:43
The producer class used in Liam
# frozen_string_literal: true
# Author: Diego Acuña
module Liam
class Producer
def initialize(event, message, options = {})
@event = event
@message = message
@options = options
end
@luctus
luctus / archdaily-ruby-test.rb
Last active July 24, 2019 19:47
Technical interview for a backend developer
#########################################
# Excercise 1: Words Count
Phrase.new("one fish two fish red fish blue fish").count
# => {"one"=>1, "fish"=>4, "two"=>1, "red"=>1, "blue"=>1}
#########################################
# Excercise 2: Acronyms
Acronym.call("hello, how are you?")
# => "H.H.A.Y"
@luctus
luctus / MostVisitedChallenge.md
Last active December 26, 2017 23:10
Most Visited Widget

The context

Due to our hight traffic we need to be very careful about how we use different cache technics in order to avoid making extra calls to our servers. We also make use of JS to load small pieces of content that should be more fresh than the whole main pages; One example of this is how we load some widgets you can see in our sidebars.

The problem

We need to generate the "Most Visited" Widget again, reading the content from this

@luctus
luctus / picking.md
Last active July 2, 2021 04:18
The picking problem

The Context

Every article is identified by a token (for example 246311). For every article we have a JSON file that contains many recommendations for that article, based on 3 different algorithms: logs, content, and myad

  • The logs algorithm finds articles visited by users that also visited the current article.
  • The content algorithm finds articles that contains similar text to the current article.
  • The myad algorithm finds articles that have been bookmarked within the same folder that the current article.

The Problem

@luctus
luctus / _google_analytics.rb
Created July 5, 2017 20:09
How to properly add Google Analytics to a Rails project
- if Rails.env.production?
:javascript
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-19488405-8', {'allowAnchor': true});
- else
@luctus
luctus / mailer.rb
Created November 15, 2016 15:36
Here you can see how to set parameters for the great Sendgrid's SMTP API (Take a look to lines 15-19) with Ruby on Rails
class ReportMailer < ApplicationMailer
def daily_email(report)
@report = report
@user = report.user
headers["X-SMTPAPI"] = {
category: report.category,
unique_args: { report: report.id, user: report.user.id }
}.to_json
@luctus
luctus / schedule.rb
Created September 20, 2016 19:37
whenever (gem) configuration for running exclusive (making sure that runs only once a time) tasks
job_type :exclusive_rake, "cd :path && flock -n 'tmp/pids/cron_:task.lock' -c ':environment_variable=:environment bundle exec rake :task --silent --backtrace :output'"
every 1.minute do
exclusive_rake "dailytics:run"
end
@luctus
luctus / chart_statificator.rb
Created August 4, 2016 20:02
Ruby module that generates a static jpg chart using the HighCharts servers
module ChartStatificator
extend ActiveSupport::Concern
# need test
def generate_static_chart
Rails.logger.debug ">>> static_chart for #{id} <<<"
data = {
'options': {series: chart.series_data,
title: chart.options[:title],
yAxis: {title: {text: nil}, labels:{}},
@luctus
luctus / app.rb
Created April 21, 2016 20:42
Example of a mini application using the Cuba framework (ruby) + HAML render engine + i18N
require "cuba"
require "cuba/render"
require "tilt/haml"
require "sass"
require "i18n"
require "i18n/backend/fallbacks"
Cuba.plugin Cuba::Render
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)