Skip to content

Instantly share code, notes, and snippets.

View Uysim's full-sized avatar
🌏
Remote

Uysim Uysim

🌏
Remote
View GitHub Profile
class MillisecondsDateTime < ActiveRecord::Migration
def up
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.connection.columns(table).each do |column|
if column.type == :datetime
change_column table, column.name, :datetime, limit: 6
add_index table, column.name
end
end
end
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs docker rmi
# remove unused volumes:
docker volume ls -f dangling=true | awk '{ print $2 }' | xargs docker volume rm
@Uysim
Uysim / generate-rails-app.md
Created December 26, 2018 07:04
Command generate rails app
rails new SampleDockerRails --database=postgresql
@Uysim
Uysim / capystrano-passenger.md
Last active January 28, 2019 06:43
Automate deployment with Capystrano Rails passenger

Setting up new Ubuntu 14.04 server with Nginx, Passenger, Postgresql, RVM, Ruby, Rails

Step 0: Setting up the new EC2 instance

NOTE: We can now use an AMI for this. Once you enter the launch wizard make sure that "My AMIs" and "Shared with me" is selected and then search for the term "Rotati". Select the Rotati Staging AMI and continue with the wizard. This AMI will have everything you need to run the staging application (so no need to run though the process below if everything is working on the AMI already!)

  • Launch the AWS instance in Singapore region (unless the client specially stated to launch in a different region). For Staging use t2.micro. For Production use t2.micro (and higher).
  • Configure the settings as per the wizard. Ensure to enable termination protection. Most other settings can remain unchanged.
  • Create a new security group for the server giving it a meaningful name (e.g. the name of the project). Open only the ports that are required which are generally HTTP, HTTPS and SSH.
@Uysim
Uysim / script.rb
Created November 18, 2019 03:43
Change Link target to blank with Nokogiri
html = '<a href="https://google.com"></a>'
fragment = Nokogiri::HTML::fragment(html)
fragment.css('a[href]').each do |link|
link.set_attribute('target', '_blank')
end
fragment.to_html
ActionMailer::Base.smtp_settings = {
address: 'premium47.web-hosting.com',
port: 465,
authentication: 'plain',
enable_starttls_auto: true,
user_name: 'admin@peer2art.com',
password: '2chb3ne4n!'
}
ActionMailer::Base.mail(
# This is to enable WS support. Credits: # https://gist.github.com/Bubelbub/0a942a0d51a3d329897d
# THIS WORKS! for running the example 5.0.0.beta1 chat app on a single instance Elastic beanstalk AWS instance
files:
"/etc/nginx/conf.d/elasticbeanstalk/00_webapp.conf" :
content: |
upstream backend {
server unix:///var/run/puma/my_app.sock;
}