Instantly share code, notes, and snippets.


Setup Rails and Vuejs

  1. Generate new rails app using --webpack flag
rails new myApp --webpack=vue


  1. You can use --webpack=angular for angular application and --webpack=react for react.


Install Postgres 11, and then:

sudo pg_dropcluster 11 main --stop
sudo pg_upgradecluster 10 main
sudo pg_dropcluster 10 main


Install Postgres 9.5, and then:

sudo pg_dropcluster 9.5 main --stop
sudo pg_upgradecluster 9.3 main
sudo pg_dropcluster 9.3 main
View database.rake
namespace :db do
namespace :structure do
desc "Overriding the task db:structure:dump task to remove -i option from pg_dump to make postgres 9.5+ compatible"
task dump: [:environment, :load_config] do
config = ActiveRecord::Base.configurations[Rails.env]
filename = File.join(Rails.root, "db", "structure.sql")
database = config["database"]
command = "pg_dump -s -x -O -f #{Shellwords.escape(filename)} #{Shellwords.escape(database)}"
module MediaManager
class VideoFile
def self.compute_hash(file_path : String)
filesize = File.size(file_path)
hash = filesize
# Read 64 kbytes, divide up into 64 bits and add each
# to hash. Do for beginning and end of file., "rb") do |f|

First, configure better_errors gem config/environments/development.rb:

BetterErrors.editor = "atom://open?url=file://%{file}&line=%{line}"

Next, create a new desktop entry /usr/share/applications/atom-urihandler.desktop:

[Desktop Entry]
Comment=Open atom:// links in Atom editor
GenericName=URI handler
View gist:7502268f28695b4e29a0
<!-- Modal Filtro -->
<div class="modal fade" id="ModalFilter" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
<%= form_tag countries_path, method: :get do %>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
<h4 class="modal-title" id="ModalLabel">Filtro</h4>
View gist:364acf1559fbad363847
require 'rubygems'
require 'mechanize'
require 'pp'
a = { |agent|
agent.user_agent_alias = 'Mac Safari'
a.get('') do |page|
search_result = page.form_with(:action => '/search') do |search|
search.q = 'Hello world'
View alias.txt
alias dm='rake db:migrate'
alias dmt='rake db:migrate && rake db:test:prepare'
alias dmp='RAILS_ENV=production rake db:migrate'
alias rc='rails c'
alias rg='rails g'
alias rcp='RAILS_ENV=production rails c'
alias rs='rails s'
alias rsp='RAILS_ENV=production rails s'
alias zdm='zeus rake db:migrate'
alias zdmt='zeus rake db:migrate && zeus rake db:test:prepare'
sudo echo "deb xenial-pgdg main" >> /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install postgresql-9.6 postgresql-contrib-9.6 libpq-dev
cd /tmp