Skip to content

Instantly share code, notes, and snippets.

@MakarovCode
MakarovCode / application_controller.rb
Last active March 13, 2025 23:42
Heroku dynos autoscaler with redis and sidekiq
# app/controllers/application_controller.rb
# Base controller for a Rails app integrated with Heroku Autoscaler.
# Tracks web response times and stores them in Redis for autoscaling decisions.
# Usage: Works with Heroku::Autoscaler to scale the 'web' dyno based on average response time.
# Requirements: 'redis' gem, REDIS_URL env variable set (e.g., via Heroku Redis add-on).
require 'json'
class ApplicationController < ActionController::Base
# Hook to measure response time for every action in the app
@MakarovCode
MakarovCode / gamepadviewer-n64.css
Last active October 21, 2022 05:50
Game pad viewer Nintendo 64 Game Pad Skin
/*https://gamepadviewer.com/?p=1&css=https%3A%2F%2Fgistcdn.githack.com%2FMakarovCode%2F252a177ccf619fb8fee5777ca89ec413%2Fraw%2Fa9d7fdb329f7cc82c8c954e428983dcf037f14df%2Fgamepadviewer-n64.css&map=%7B%22mapping%22%3A%5B%7B%22targetType%22%3A%22buttons%22%2C%22target%22%3A%229%22%2C%22disabled%22%3Afalse%2C%22choiceType%22%3A%22buttons%22%2C%22choice%22%3A%220%22%7D%2C%7B%22targetType%22%3A%22buttons%22%2C%22target%22%3A%228%22%2C%22disabled%22%3Afalse%2C%22choiceType%22%3A%22buttons%22%2C%22choice%22%3A%222%22%7D%2C%7B%22targetType%22%3A%22buttons%22%2C%22target%22%3A%2216%22%2C%22disabled%22%3Afalse%2C%22choiceType%22%3A%22buttons%22%2C%22choice%22%3A%229%22%7D%2C%7B%22targetType%22%3A%22buttons%22%2C%22target%22%3A%220%22%2C%22disabled%22%3Afalse%2C%22choiceOperand%22%3A%22-%22%2C%22choiceType%22%3A%22axes%22%2C%22choice%22%3A%223%22%7D%2C%7B%22targetType%22%3A%22buttons%22%2C%22target%22%3A%223%22%2C%22disabled%22%3Afalse%2C%22choiceOperand%22%3A%22%2B%22%2C%22choiceType%22%3A%22axes%22%2C%22choice%22%3A%2
@MakarovCode
MakarovCode / ascii_art.rb
Created June 5, 2021 04:28
Ruby Class to turn images into Ascii Art using braille character
require "mini_magick"
class AsciiArt
attr_accessor :path, :inverted, :size, :art
# Make sure size is in this format 100x100 or 50x600
def initialize(path, inverted=nil, size=nil)
@path = path
@inverted = inverted
@MakarovCode
MakarovCode / ruby_script.service
Created June 5, 2021 03:29
Ruby Script SystemCtl Daemon File
[Unit]
Description=gps_client
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/home/ubuntu/motosmart/current/lib
ExecStart=ruby /home/ubuntu/motosmart/current/lib/ruby_script.rb
@MakarovCode
MakarovCode / sidekiq.service
Created June 5, 2021 03:28
Sidekiq SystemCtl Daemon file
[Unit]
Description=sidekiq
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/home/rails/project/current
ExecStart=/home/rails/.rbenv/shims/bundle exec sidekiq -e production -L /home/rails/project/current/log/sidekiq.log
@MakarovCode
MakarovCode / default
Created June 5, 2021 03:26
Nginx sites-enabled for Ruby on Rails
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
@MakarovCode
MakarovCode / angular-decimalmax.js
Created November 12, 2020 14:47
AngularJS pipe filter for handling decimals up to a max
var module = angular.module('app', [])
//Just add this after you declare your main module
module.filter('decimalmax', ['$filter', function ($filter) {
return function(num, params) {
if (num == null) return 0;
var v = (num + "").split(".");
var pres = 0
if (v.length > 1){
var p = v[1].length;
if (p <= params){