Skip to content

Instantly share code, notes, and snippets.

View mpakus's full-sized avatar
💭
🏍

Ibragimov "MpaK" Renat mpakus

💭
🏍
View GitHub Profile
# Check server process is using jemalloc
# ref. [Japanese] https://tech.studyplus.co.jp/entry/2019/09/09/094140
class AppController < ActionController::Base
def show
r = `strings /proc/#{Process.pid}/maps | grep jemalloc`
render plain: "<h1>#{ENV['LD_PRELOAD'].presence || 'empty'}</h1><pre>#{r}</pre>"
end
end
@mpakus
mpakus / as3.rake
Created March 10, 2024 18:12 — forked from otobrglez/as3.rake
Rake task for uploading Rails 3.1 compiled assets to Amazon S3 storage
# 1) Put 's3' gem in Gemfile.
# 2) Create as3.yml configuration for S3
# 3) Create initializer for as3.yml
# 4) Make "assets" folder inside your bucket
# 5) After running task run "RAILS_ENV=production rake assets:precompile"
# 6) Invoke task by running "rake as3:upload"
namespace :as3 do
desc "Uploads compiled assets (public/assets) to Amazone AS3"
task :upload do
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<style>
.sidebar {
width: 5rem; /* Adjust the width as needed */
height: 100vh;
@mpakus
mpakus / sidebar.slim
Last active January 25, 2023 09:58
Bootstrap5 sidebar icons on the left chatgpt
doctype html
html lang="en"
head
meta charset="UTF-8"
meta name="viewport" content="width=device-width, initial-scale=1.0"
link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" integrity="sha384-1E9xRUaYjS4d4L/kWVd4tpq3Jkc/kWVd4tpq3Jkc" crossorigin="anonymous"
link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous"
title Bootstrap 5 Sidebar
style
| /* customize the sidebar */
@mpakus
mpakus / Rakefile
Created January 6, 2022 17:00 — forked from schickling/Rakefile
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@mpakus
mpakus / linkedin.rb
Created October 31, 2021 09:32
Shortest way to get Linkedin authorized access token
require 'sinatra'
require "sinatra/reloader" if development?
require 'http'
require 'json'
# https://www.linkedin.com/developers/apps
class Settings
CLIENT_ID = '...'
CLIENT_SECRET = '...'
ACCESS_TOKEN = '...'
@mpakus
mpakus / dijkstra.rb
Created October 27, 2021 14:19
Dijkstra's algorithm to search shortest path in Graph
class Graph
def initialize
@graph = {
"Odin" => [["Thor", 1], ["Heimdall", 1]],
"Fregg" => [["Heimdall", 1], ["Thor", 1]],
"Heimdall" => [["Odin", 1], ["Fregg", 1]],
"Thor" => [["Odin", 1], ["Loki", 1], ["Fregg", 1]],
"Loki" => [["Thor", 1]]
}
end
@mpakus
mpakus / test.rb
Created September 21, 2021 16:30 — forked from le0pard/test.rb
unlogged tables in rails for test env
# unlogged tables used to speedup tests, but its are not crash proof
config.to_prepare do
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true
end
end
@mpakus
mpakus / Caddyfile
Created July 9, 2020 15:30
Caddyfile for Rails app
http://site.com http://www.site.com https://www.site.com {
redir https://site.com{uri}
}
https://site.com {
root * /var/www/site/current/public
log {
output file /var/www/site/shared/log/access.log {
roll_size 10MB
@mpakus
mpakus / README.md
Created June 30, 2020 06:30 — forked from pcreux/README.md
Failsafe: degrade user experience and notify when something goes wrong.

Failsafe

When something goes wrong I want to degrade the user experience (instead of returning a 500 - Server Error) And I want to be notified about the failure

Usage

Wrap non mission critical code: