Skip to content

Instantly share code, notes, and snippets.

View luizkowalski's full-sized avatar
:atom:
bug fixes and performance improvements

Luiz Eduardo Kowalski luizkowalski

:atom:
bug fixes and performance improvements
View GitHub Profile
@luizkowalski
luizkowalski / update.rb
Last active August 30, 2024 18:46
Check if there are any new images available for Kamal accessories
#!/usr/bin/env ruby
# frozen_string_literal: true
# Lives in .kamal/update
require "json"
require "net/http"
require "uri"
require "yaml"
@luizkowalski
luizkowalski / deploy.yml
Created June 16, 2024 10:14
Grafana and Prometheus on Kamal
grafana:
image: grafana/grafana-enterprise:10.4.4-ubuntu
host: web
port: "3030:3000"
env:
clear:
GF_SERVER_ROOT_URL: your_url
GF_INSTALL_PLUGINS: grafana-clock-panel,redis-datasource,yesoreyeram-infinity-datasource
labels:
traefik.http.routers.grafana.rule: Host(`grafana.sumiu.link`) || (Host(`grafana-api.sumiu.link`) && PathPrefix(`/api`))
@luizkowalski
luizkowalski / rails_cloc.sh
Last active May 2, 2018 14:34 — forked from nlively/rails_cloc.sh
Count lines of code in a rails project
#!/bin/bash
find . \( -iname '*.rb' -o -iname '*.jb' -o -iname '*.erb' -o -iname '*.rake' \) -not -path "./spec/*" -not -path "./db/*" -exec wc -l {} + | sort -n
kubectl get pods --show-all=true | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
@luizkowalski
luizkowalski / base_controller.rb
Created September 22, 2016 10:16 — forked from dhoelzgen/base_controller.rb
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'

Keybase proof

I hereby claim:

  • I am luizkowalski on github.
  • I am luizkowalski (https://keybase.io/luizkowalski) on keybase.
  • I have a public key whose fingerprint is A435 CA7D 4469 2F6A CD41 BA80 2294 EF90 7412 EC21

To claim this, I am signing this object:

@luizkowalski
luizkowalski / gist:a7140af53bd64aa82a65
Created February 23, 2016 22:11 — forked from rakasaka/gist:1169341
Unsupervised topic modeling in Ruby using LDA
require 'lda-ruby'
corpus = Lda::Corpus.new
corpus.add_document(Lda::TextDocument.new(corpus, "a lion is a wild feline animal", []))
corpus.add_document(Lda::TextDocument.new(corpus, "a dog is a friendly animal", []))
corpus.add_document(Lda::TextDocument.new(corpus, "a cat is a feline animal", []))
lda = Lda::Lda.new(corpus)
lda.verbose = false
lda.num_topics = (2)
lda.em('random')
match = { "$match" => { "$messages.created_at" => { "$gte" => 1.day.ago } } }
group = { "$group" => { _id: '$messages', count: {"$sum" => 1 } } }
sort = { "$sort" => { count: -1 } }
limit = { "$limit" => 3 }
Room.collection.aggregate([match, group, sort, limit])
# The classes
class ReducaoZ < ActiveRecord::Base
self.table_name = 'reducaoz'
belongs_to :empresa
belongs_to :impressorafiscal, foreign_key: 'impressorafiscal_id', class_name: 'ImpressoraFiscal'
belongs_to :usuario_cadastro, foreign_key: 'usuariocadastro_id', class_name: 'Usuario'
belongs_to :usuario_alteracao, foreign_key: 'usuarioalteracao_id', class_name: 'Usuario'
has_many :aliquotas, primary_key: 'id', foreign_key: 'reducaoz_id', class_name: 'Aliquota', dependent: :delete_all
(1.0ms) BEGIN
SQL (1.6ms) INSERT INTO "movimentacaocontabil" ("avulsa", "dataalteracao", "datacadastro", "datamovimentacao", "empresa_id", "filial", "lote", "valor") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["avulsa", "t"], ["dataalteracao", "2014-05-20 18:50:25.841362"], ["datacadastro", "2014-05-20 18:50:25.841078"], ["datamovimentacao", "2014-05-19"], ["empresa_id", 32], ["filial", "f"], ["lote", 783], ["valor", "5160.69"]]
SQL (1.8ms) INSERT INTO "lancamentocontabil" ("conta_id", "datacadastro", "datalancamento", "empresa_id", "filial", "historico", "tipo", "valor") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["conta_id", 406258], ["datacadastro", "2014-05-20 18:50:25.863252"], ["datalancamento", "2014-05-19 03:00:00.000000"], ["empresa_id", 32], ["filial", "f"], ["historico", "PROGER FINANCIAMENTO PLATAFORMAS"], ["tipo", "D"], ["valor", "5160.69"]]
SQL (2.5ms) INSERT INTO "movimentacaocontabil_lancamentocontabil" DEFAULT VALUES RETURNING "movimentacaocontabil_id"
P