Skip to content

Instantly share code, notes, and snippets.

View brodock's full-sized avatar

Gabriel Mazetto brodock

View GitHub Profile
@brodock
brodock / wake-up-light-alarm-with-sunrise-effect.yaml
Created February 2, 2024 14:56 — forked from triplepoint/wake-up-light-alarm-with-sunrise-effect.yaml
Home Assistant Blueprint: Wake-up light alarm with sunrise effect
blueprint:
name: Wake-up light alarm with sunrise effect
description:
"A wake-up light alarm with a brightness and color temperature sunrise
effect. Note: not manually executable!"
domain: automation
input:
light_entity:
name: Wake-up light entity
description:
@brodock
brodock / capture-age.sh
Created August 13, 2023 15:03
Capture Age on Linux
#!/bin/bash
set -x
PROTON="GE-Proton8-4"
APPID=813780
CAPTURE_AGE_VERSION=1.6.1
STEAM_PATH="${HOME}/.steam"
STEAMAPPS="${STEAM_PATH}/root/steamapps"
COMPATIBILITY_TOOLS="${STEAM_PATH}/root/compatibilitytools.d"
@brodock
brodock / HueDimmer_RWL022.yaml
Last active November 11, 2023 18:40
Philips Hue Dimmer RWL022
blueprint:
name: Philips Hue Dimmer RWL022
description:
"Control lights with a Philips Hue Dimmer Switch (v2).\n\n Blueprint\
\ Version: 2"
domain: automation
input:
remote:
name: Philips Hue Dimmer Switch
description: Pick a RWL022 Dimmer Switch
@brodock
brodock / stacktrace.txt
Created April 4, 2020 10:02
hamlit stacktrace
This file has been truncated, but you can view the full file.
/builds/gitlab-org/gitlab/app/views/projects/new.html.haml:53: [BUG] Segmentation fault at 0x0000000000000038
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0211 p:---- s:1376 e:001375 CFUNC :build_class
c:0210 p:1228 s:1369 E:000480 METHOD /builds/gitlab-org/gitlab/app/views/projects/new.html.haml:53
c:0209 p:0039 s:1328 e:001327 METHOD /builds/gitlab-org/gitlab/vendor/ruby/2.6.0/gems/actionview-6.0.2/lib/action_view/base.rb:274
c:0208 p:0026 s:1316 e:001315 BLOCK /builds/gitlab-org/gitlab/vendor/ruby/2.6.0/gems/actionview-6.0.2/lib/action_view/template.rb:185
c:0207 p:0039 s:1313 e:001312 METHOD /builds/gitlab-org/gitlab/vendor/ruby/2.6.0/gems/activesupport-6.0.2/lib/active_support/notifications.rb:182
c:0206 p:0022 s:1307 e:001306 METHOD /builds/gitlab-org/gitlab/vendor/ruby/2.6.0/gems/actionview-6.0.2/lib/action_view/template.rb:386
@brodock
brodock / Procfile
Last active March 19, 2018 23:31
Ruby no Mac em algumas linhas
# create path and copy redis.conf to the correct path
redis: exec redis-server /Users/youruser/projects/yourproject/dev/redis/redis.conf
# path/to/postgres/initdb --locale=C -E utf8 /Users/youruser/projects/yourproject/dev/postgresql/data
postgresql: exec postgres -D /Users/youruser/projects/yourproject/dev/postgresql/data -k /Users/youruser/projects/yourproject/dev/postgresql -h 'localhost'

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add the sidekiq_profiler.rb (below) to your project

Adjust number of jobs you want your worker to process before you have heap dumped.
Run a sample worker: PROFILE=1 sidekiq -C config/sidekiq.yml and wait for jobs to be processed.

require 'therubyracer'
require 'commonjs'
webpack_path = `which webpack`.chomp
webpack_content = File.open(webpack_path).read.sub("#!/usr/bin/env node\n", '')
ctx = V8::Context.new
env = CommonJS::Environment.new(ctx, path: '/usr/local/lib/node_modules')
ctx['require'] = lambda { |this, module_id| env.require(module_id) }
@brodock
brodock / download.js
Last active September 9, 2016 16:31
Download all Dreamhost Backups
// run this inside the javascript console of the Backups page:
urls = $x('/html/body/div/div/div[4]/table/tbody/tr//a')
urls.forEach(function(e) { console.log('curl "' + e.href + '"' + ' -o "' + e.innerHTML + '"') })
// It will output a ready to use list of wget commands that will download every backup file
// If the console adds line numbering or other useless data like in chrome, try this instead:
urls = $x('/html/body/div/div/div[4]/table/tbody/tr//a')
var wget_list = ""
urls.forEach(function(e) { wget_list = wget_list + 'curl "' + e.href + '"' + ' -o "' + e.innerHTML + "\" \n" })
console.log(wget_list)
@brodock
brodock / keybase.md
Created November 18, 2015 21:43
Keybase proof

Keybase proof

I hereby claim:

  • I am brodock on github.
  • I am brodock (https://keybase.io/brodock) on keybase.
  • I have a public key whose fingerprint is 4E65 23FE 0082 24ED 42E3 F4BA D9C6 74CE 5B99 059F

To claim this, I am signing this object:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# ...
config.vm.provision 'shell', inline: <<-SCRIPT
curl -s -L -O https://github.com/brodock/apt-select/releases/download/0.1.0/apt-select_0.1.0-0_all.deb && sudo dpkg -i apt-select_0.1.0-0_all.deb
apt-select && sudo apt-select-update
SCRIPT
#...
end