Friday, 13 October 2017

Monday, 9 October 2017

Install Skype in Ubuntu system: 

sudo add-apt-repository "deb http://archive.canonical.com/ $(lsb_release -sc) partner"

Add i386 architecture
sudo dpkg --add-architecture i386

Update and install

sudo apt-get update && sudo apt-get install skype

Tuesday, 25 July 2017

Code Customization

https://github.com/eliotsykes/rails-security-checklist
https://www.owasp.org/index.php/Ruby_on_Rails_Cheatsheet
https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/

Heroku Commands


  • db:migrate runs (single) migrations that have not run yet.
  • db:create creates the database
  • db:drop deletes the database
  • db:schema:load creates tables and columns within the (existing) database following schema.rb
  • db:setup does db:create, db:schema:load, db:seed
  • db:reset does db:drop, db:setup
Typically, you would use db:migrate after having made changes to the schema via new migration files (this makes sense only if there is already data in the database). db:schema:load is used when you setup a new instance of your app.
I hope that helps.

UPDATE for rails 3.2.12:
I just checked the source and the dependencies are like this now:
  • db:create creates the database for the current env
  • db:create:all creates the databases for all envs
  • db:drop drops the database for the current env
  • db:drop:all drops the databases for all envs
  • db:migrate runs migrations for the current env that have not run yet
  • db:migrate:up runs one specific migration
  • db:migrate:down rolls back one specific migration
  • db:migrate:status shows current migration status
  • db:rollback rolls back the last migration
  • db:forward advances the current schema version to the next one
  • db:seed (only) runs the db/seed.rb file
  • db:schema:load loads the schema into the current env's database
  • db:schema:dump dumps the current env's schema (and seems to create the db as well)
  • db:setup runs db:schema:load, db:seed
  • db:reset runs db:drop db:setup
  • db:migrate:redo runs (db:migrate:down db:migrate:up) or (db:rollback db:migrate) depending on the specified migration
  • db:migrate:reset runs db:drop db:create db:migrate
WunderGround API: 

wu_data.rb

# encoding: UTF-8

require "json"
require "open-uri"
require_relative 'wu'
require_relative 'forecast_io'

class WuData
  URL_API = "http://54.68.32.124"
  def initialize
    places = open(URL_API+"/sync_places").read
    @places = JSON.parse places
  end

  def get_wu
    @wu_data = {}
    @places.each do |place|
      query_start_time = DateTime.now
      _coords = "#{place["location"][0]}"+","+"#{place["location"][1]}"
      puts "#{_coords}===================="
      wu = Wu.new(_coords)
      wu_obj = wu.report
      @wu_data[place["id"]] = wu_obj
      sleep 1
      puts "  -> #{((DateTime.now - query_start_time) * 24 * 60 * 60).to_f}s"
    end
  end

  def wu_json
    File.open("wu_json/wu_data.json","w") do |f|
      f.write(@wu_data.to_json)
    end
  end
end

wu = WuData.new
wu.get_wu
wu.wu_json


sync_data.rb


Phone type format with javascript

<script type='text/javascript' src='http://digitalbush.com/wp-includes/js/jquery/jquery.js?ver=1.11.0'></script>
<script type="text/javascript" src="http://digitalbush.com/wp-content/uploads/2014/10/jquery.maskedinput.js"></script>


<script>
    jQuery(function($){       
       $(".phone").mask("(999) 999-9999");
    });
</script>    

File Handling operations (Read, Write, Open)


controller:-i
       f !Dir.exists?("public/default_sms")
          default_sms(params)
        else
          update_sms(params)
        end


  def default_sms(params)
    FileUtils.mkdir_p "#{Rails.public_path}/default_sms"
    @team_sms = File.open(Rails.root.join("public/default_sms","team_sms.txt"), 'w') do |file|     
      file.write(params[:notification][:team_sms])
    end
  end

  def update_sms(params)
    FileUtils.mkdir_p "#{Rails.public_path}/update_sms_#{current_user.id}"
    @team_sms = File.open(Rails.root.join("public/update_sms_#{current_user.id}","team_sms_#{current_user.id}.txt"), 'w') do |file|     
      file.write(params[:notification][:team_sms])
    end
end


View: check whether exists or not
    Dir.glob("public/update_sms_#{current_user.id}").present? ? File.read(Rails.root.join("public/update_sms_#{current_user.id}/team_sms_#{current_user.id}.txt")) : Dir.glob("public/default_sms").present? ? File.read(Rails.root.join("public/default_sms/team_sms.txt")) : nil