Skip to content

Instantly share code, notes, and snippets.

View Uysim's full-sized avatar
🌏
Remote

Uysim Uysim

🌏
Remote
View GitHub Profile
# 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;
}
@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
@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 / generate-rails-app.md
Created December 26, 2018 07:04
Command generate rails app
rails new SampleDockerRails --database=postgresql
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(
#!/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
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 / laravel.js
Created June 6, 2017 06:53 — 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.
/*
<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 10:56
This gist is rake for rails copy digest to nondigest assets
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, '.'
@Uysim
Uysim / js_datetime.js
Created January 3, 2017 09:58
This gist describe about how to work with js DateTime
// Get current date time
var currentDate = new Date();
// get date
var date = currentDate.getDate();
// get month index (January is 0)
var month = currentDate.getMonth();
// get year