Skip to content

Instantly share code, notes, and snippets.

View pvin's full-sized avatar

praaveen vr pvin

View GitHub Profile
@pvin
pvin / hello.exs
Created November 21, 2015 09:28
hello world in elixir
IO.puts "hello world!"
events/_forms.html.erb
<div class="form-group test">
<%= f.label :auctions, class: "col-lg-4 col-sm-2 control-label required" %>
<div class="col-lg-8" id="filter">
<%= f.collection_select :auction_ids, filter_auction, :id, :name, {}, {:multiple => true, class: "form-control acution-class", required: true}%>
</div>
</div>
<script>
@pvin
pvin / rb
Created May 29, 2016 10:06
Carefull with processing array index, ruby. (reference : Eloquent ruby)
#The easiest way to screw up one of these iterating methods is to change the collection out from underneath the method.
#Here, for example, is a seriously misguided attempt to remove all of the negative numbers from an array:
array = [ 0, -10, -9, 5, 9 ]
array.each_index {|i| array.delete_at(i) if array[i] < 0}
pp array
#The trouble with this code is that it will tend to leave some negative numbers behind: Removing the first one (the -10 ) from
#the array messes up the internal indexing of the each method, so much that it will miss the second negative number, leaving
#us with a result of:
#Usual way
unique = []
words.each { |word| unique << word unless unique.include?(word) }
#What we really need is a collection that doesn’t allow duplicates but does feature very fast and easy answers to the “is this
#object in there?” question. The punch line is that we need a set. Fortunately, Ruby comes with a perfectly serviceable, if
#sometimes forgotten,
#Set class:
puts 'yes yes'.sub( 'yes', 'no' )
=> no yes
puts 'yes yes'.gsub( 'yes', 'no' )
=> no no
Rspec::
rspec
rspec spec/models
rspec spec/controllers/accounts_controller_spec.rb
rails generate rspec:model
/factories /support /models /controllers /features /views /mailers /routing /helpers
Model spec - behavior of model
require "rails_helper"
@pvin
pvin / gist:51b55937e979ccf09d358d26c88c215d
Created October 19, 2017 10:35
ufw for blocking the ports
Connect to Server(ssh)
sudo apt-get install ufw
sudo ufw allow 80 (port http)
sudo ufw allow 443 (port https)
sudo ufw allow 22 (port SSH)
sudo ufw enable
sudo ufw reload
sudo ufw status (will list all open ports)
begin
ActiveRecord::Base.transaction do
User.create(name: 'test')
Role.create(name:'manager')
end
rescue => e
raise ActiveRecord::Rollback
end
@pvin
pvin / gist:86f8cc560d4098adf54482a10ea7c798
Last active December 3, 2017 12:28
How to run the rails 5 application in production mode?
Change in config/environments/production.rb
config.assets.compile = true
Change in config/initializers/devise.rb
config.secret_key = '34790ca67ba55291b876053e2de5a248059345fd3994ada01bc4f16a4b272dedcffdee6c71f9a4b3a92773462686c9ee4a0753b02efcc26d14e6ee11cb9fc9c6'
Change in config/secrets.yml
secret_key_base: 32790ca67ba55234b876053e2de5a248059345fd3994ada01bc4f16a4b272dedcffdee6c71f9a4b3a92773462686c9ee4a0753b02efcc26d14e6ee11cb9fc9c6
Configure database.yml with production env
@pvin
pvin / gist:4ff1a64da96852683c6541daf8c45bd5
Created December 7, 2017 16:04
Backup and Restore a database of mssql
sqlcmd -S localhost -U SA -Q "BACKUP DATABASE web_ilids_development TO DISK = N'/var/opt/mssql/data/web_ilids_development.bak' WITH NOFORMAT, NOINIT, NAME = 'web_ilids_development-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-backup-and-restore-database
https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools#ubuntu