Skip to content

Instantly share code, notes, and snippets.

View tvcam's full-sized avatar
🏠
Working from home

Vibol tvcam

🏠
Working from home
View GitHub Profile
@tvcam
tvcam / gist:653be3b7c922c4d05c4f1be8baeebeee
Created November 10, 2022 13:51
Systemd shutting down when terminal is closed
You’re running the service from your user manager (--user), and apparently your logind doesn’t have lingering enabled for you. As a result, your session (including any services started inside it) is closed down whenever you log out.
To change this behaviour, you need to enable lingering:
`sudo loginctl enable-linger $USER`
This will start a user manager for you at boot and allow your services to survive your login sessions.
A better approach for a system service such as this is really to run it as its own user, managed by the main systemd instance.
@tvcam
tvcam / ubuntu-20.04
Last active October 9, 2021 16:31
Setup RoR web server - Ubuntu 20.04
# Apache
sudo apt-get install -y apache2
# Install our PGP key and add HTTPS support for APT
sudo apt-get install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
# Install Passenger + Apache module
sudo apt-get install -y libapache2-mod-passenger
@tvcam
tvcam / therubyracer.txt
Last active March 9, 2020 11:26
Fail to install therubyracer in Mac
brew install v8@3.15
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8@3.15
bundle install
@tvcam
tvcam / no_rmagick
Last active December 26, 2018 11:26
Don't use RMagick
I worked for a client where I have to generate an image version to be display in frontend (old code use original image which size ~6MBx40images for a gallery). I added a new image version in ImageUploader class then run a background job to reprocess large version. The website keep crashing every 20mn, after the whole day debugging the job, debugging sidekiq, trying uncached query, result still the same.
After a whole day I found the issue, it caused by RMagick. I migrate to MiniMagick which is a replacement for RMagick.
https://github.com/minimagick/minimagick
"I was using RMagick and loving it, but it was eating up huge amounts of memory. Even a simple script would use over 100MB of RAM. On my local machine this wasn't a problem, but on my hosting server the ruby apps would crash because of their 100MB memory limit."
So choose a gem carefully!
CGA git:(develop) gem install rmagick -v '2.16.0'
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
current directory: /Users/vibolteav/.rvm/gems/ruby-2.3.4@caregiverasia/gems/rmagick-2.16.0/ext/RMagick
/Users/vibolteav/.rvm/rubies/ruby-2.3.4/bin/ruby -r ./siteconf20180109-46784-15zo51o.rb extconf.rb
checking for gcc... yes
checking for Magick-config... yes
checking for outdated ImageMagick version (<= 6.4.9)... no
An error occurred while installing nokogiri (1.8.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.8.1'` succeeds before bundling.
In Gemfile:
activeadmin_settings_cached was resolved to 2.0.1, which depends on
rails-settings-cached was resolved to 0.5.6, which depends on
rails was resolved to 5.0.6, which depends on
actioncable was resolved to 5.0.6, which depends on
actionpack was resolved to 5.0.6, which depends on
actionview was resolved to 5.0.6, which depends on