Skip to content

Instantly share code, notes, and snippets.

Working from home

Uysim Uysim

Working from home
View GitHub Profile
View .ebextensions\nginx_proxy.config
# This is to enable WS support. Credits: #
# THIS WORKS! for running the example 5.0.0.beta1 chat app on a single instance Elastic beanstalk AWS instance
"/etc/nginx/conf.d/elasticbeanstalk/00_webapp.conf" :
content: |
upstream backend {
server unix:///var/run/puma/my_app.sock;
Uysim / script.rb
Created Nov 18, 2019
Change Link target to blank with Nokogiri
View script.rb
html = '<a href=""></a>'
fragment = Nokogiri::HTML::fragment(html)
fragment.css('a[href]').each do |link|
link.set_attribute('target', '_blank')
Uysim /
Last active Jan 28, 2019
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 /
Created Dec 26, 2018
Command generate rails app
rails new SampleDockerRails --database=postgresql
View test_smtp_rails
ActionMailer::Base.smtp_settings = {
address: '',
port: 465,
authentication: 'plain',
enable_starttls_auto: true,
user_name: '',
password: '2chb3ne4n!'
# 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,, :datetime, limit: 6
add_index table,
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 / 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
nondigest = file.sub fingerprint, '.'
Uysim / js_datetime.js
Created Jan 3, 2017
This gist describe about how to work with js DateTime
View js_datetime.js
// 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