Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Uysim Uysim

🏠
Working from home
View GitHub Profile
View .ebextensions\nginx_proxy.config
# 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;
}
View test_smtp_rails
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(
@Uysim
Uysim / script.rb
Created Nov 18, 2019
Change Link target to blank with Nokogiri
View script.rb
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
@Uysim
Uysim / capystrano-passenger.md
Last active Jan 28, 2019
Automate deployment with Capystrano Rails passenger
View capystrano-passenger.md

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 / generate-rails-app.md
Created Dec 26, 2018
Command generate rails app
View generate-rails-app.md
rails new SampleDockerRails --database=postgresql
View cleanup-docker.sh
#!/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
View change-datetime-column.rb
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
@Uysim
Uysim / move-carrierwave-image-from-s3-to-local.rb
Created Nov 1, 2016
this gist code use for move your carrirerwave file from assets s3 of amazon to you local file.
View move-carrierwave-image-from-s3-to-local.rb
CarrierWave.configure do |config|
config.storage = :fog
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: ENV['FOG_REGION']
}
config.fog_directory = ENV['S3_BUCKET_NAME']
end
@Uysim
Uysim / laravel.js
Created Jun 6, 2017 — forked from JeffreyWay/laravel.js
Want to send a DELETE request when outside of a form? This will handle the form-creation bits for you dynamically, similar to the Rails implementation. (Requires jQuery, but doesn't have to.) To use, import script, and create a link with the `data-method="DELETE"` attribute.
View laravel.js
/*
<a href="posts/2" data-method="delete"> <---- We want to send an HTTP DELETE request
- Or, request confirmation in the process -
<a href="posts/2" data-method="delete" data-confirm="Are you sure?">
*/
(function() {
@Uysim
Uysim / nondigest_assets.rake
Created May 21, 2017
This gist is rake for rails copy digest to nondigest assets
View nondigest_assets.rake
namespace :nondigest do
desc "TODO"
task precompile: :environment do
fingerprint = /\-[0-9a-f]{64}\./
filemap = {}
Dir["public/assets/**/*"].each do |file|
next if file !~ fingerprint
next if File.directory?(file)
nondigest = file.sub fingerprint, '.'