Posts

Run sidekiq in proudction mode

##To Update cron bundle exec whenever --update-crontab ## To start Redis redis-server ##clear rediscache redis-cli flushall ## To Start Sidekiq in production env bundle exec sidekiq -d -L sidekiq.log -q mailer,5 -q default -e production ## compile assets rake assets:precompile RAILS_ENV=production

ActionCable Devise Authentication

ActionCable is a new framework for real-time communication over websockets and it will be part of Rails 5. I am not going to get into too much detail about it, you can read the very detailed readme of the project on this link: ActionCable . The websockets server is running in a separate process from the main Rails application which means you need to authenticate your users there too. In the example app , David used a simple cookie based authentication in the app itself and re-validated the cookie at the websocket connection. This is good for demonstration, but many of the Rails based apps are using Devise for authentication so I want to share, how I solved the authentication with Devise. The websocket server doesn't have a session, but it can read the same cookies as the main app, so I figured, I will just set a cookie with the user id and verify that at the socket connection. To do this, I used a Warden hook: # app/config/initializers/warden_hooks.rb Warden ::

Conver mysql .sql file in to postgreql .psql

1. mysqldump --compatible=postgresql --default-character-set=utf8 -r marketacreative.mysql -u root marketacreative 2. python db_converter.py marketacreative.mysql marketacreative.psql Get db_converter.py from https://github.com/lanyrd/mysql-postgresql-converter 3. psql -U root -h localhost -d marketacreative -f  marketacreative.psql  

Install development library in ubuntu

sudo apt - get install libgmp3 - dev

New gem not installing on server

bundle install --path vendor/bundle bundle package --all

has_many association with polymorphic in ruby on rails

rails g model member user_id:integer  invitable_id:integer invitable_type:string class Member < ActiveRecord::Base     belongs_to :user     belongs_to :invitable, polymorphic: true end User can join many communities, groups and meeting rooms, so the has many polymorphic association will look like as:- class User < ActiveRecord::Base   has_many :members, dependent: :destroy   has_many :community_members, through: :members, source: :invitable, source_type: 'Community'   has_many :group_members, through: :members, source: :invitable, source_type: 'Group'   has_many :meeting_rooms_members, through: :members, source: :invitable, source_type: 'MeetingRoom'   has_many :meeting_rooms, dependent: :destroy end

remove html tags from html

html = ' <b><a href="http://foo.com/">foo</a></b><img src="bar.jpg"> '   ActionView :: Base . full_sanitizer . sanitize ( html )

create git hook to push code on server

Login to the server   ssh root@IP   sudo apt-get update sudo apt-get install apache2   Again, we should give ownership of the document root to the user we are operating as: sudo chown -R `whoami`:`id -gn` /var/www/html   We need to remember to install git on this machine as well: sudo apt-get install git Now, we can create a directory within our user's home directory to hold the repository. We can then move into that directory and initialize a bare repository. A bare repository does not have a working directory and is better for servers that you will not be working with much directly: m kdir ~/proj  cd ~/proj  git init --bare   Since this is a bare repository, there is no working directory and all of the files that are located in .git in a conventional setup are in the main directory itself. We need to create another git hook. This time, we are interested in the post-receive hook, which is run on the server receiving a git push . Open this

How to pass hash in Postman

By the looks of what you are trying to send, you need to change the Grape restriction, because destinations is an Array , not a Hash : requires : destinations , type : Array   You don't need the "destination" hash when sending the request: { destinations => [ { name => 'dest1' , other_attribute : 'value' , etc ... }, { name => 'dest2' , other_attribute : 'value' , etc ... }, { name => 'dest3' , other_attribute : 'value' , etc ... } ]}   This creates an Array of hashes. In order to send this through POSTMAN, you'll need to modify that destinations param your sending and add multiple lines in POSTMAN. Something like: destinations [][ name ] 'dest1' destinations [][ other_attribute ] 'value1' destinations [][ name ] 'dest2' destinations [][ other_attribute ] 'value2'

message system in ruby on rails

1- Create message model:-  rails g model message sender_id:integer recepient_id:integer body:text 2- Define Assosciation and scopes:-  class Message < ActiveRecord::Base     belongs_to :sender,      :class_name => 'User',      :foreign_key => 'sender_id'     belongs_to :recepient,      :class_name => 'User',      :foreign_key => 'recepient_id'     scope :conversations, lambda{|sender_id,recepient_id| where('sender_id = ? AND recepient_id = ? ',sender_id, recepient_id ).order("created_at DESC")}     scope :friends_conversations, lambda{|recepient_id,sender_id| where('sender_id = ? AND recepient_id = ? ',sender_id, recepient_id ).order("created_at DESC")} end 3- User model:- class User < ActiveRecord::Base  has_many :received_messages,  :class_name => 'Message',  :foreign_key => 'recepient_id'  has_many :sent_messages,  :class_name => 'Message'

UBUNTU Wi-Fi hotspot is not detected by android phone

Image
Share Internet Connection With Android in Ubuntu 14.04 June 8, 2014 —  127 Comments This quick tip is going to show you how to create wifi hotspot in Ubuntu 14.04 so that you can share a wired internet connection with Android devices through your wireless card. I’ve written about this in another post using a third-party app called ap-hotspot , but some readers said that not work. The pre-installed Network Manager in Ubuntu Unity does not support Access Point (AP) mode which is required for Android devices. Fortunately, KDE’s connection editor support this mode, below is how: NOTE: To do below steps, your Wireless Card must support Access Point (AP) mode. 1. Click the link below to bring up Ubuntu Software Center and click install kde-nm-connection-editor: Click Install KDE’s Network Manager 2. Once installed, press Alt+F2 and run command to launch the app: kde-nm-connection-editor 3. Cli

import data from csv to postgresql

sudo -u postgres psql   Postgresql to csv file:-   COPY products TO '/home/products.csv' DELIMITER ',' CSV HEADER ; CSV to Postgresql table:-   COPY products FROM '/home/products.csv' DELIMITER ',' CSV HEADER ;   products is table name.

run multiple applications on same ip using nginx

server {         listen 80 default_server;         listen [::]:80 default_server;         # SSL configuration         #         # listen 443 ssl default_server;         # listen [::]:443 ssl default_server;         #         # Self signed certs generated by the ssl-cert package         # Don't use them in a production server!         #         #root /usr/share/nginx/html;         server_name 108.174.155.117;         passenger_enabled on;         rails_env    production;         root         /home/app/test-runner/public;          error_page   500 502 503 504  /50x.html;         #location = /50x.html {         #    root   html;         #}         # Add index.php to the list if you are using PHP         index index.html index.htm index.nginx-debian.html;         #server_name _;          #server_name _;         #location / {                 # First attempt to serve request as file, then                 # as directory, then fall back to displaying a 404.         #       try_files $uri

AWS Elastic Beanstalk - Using eb to attach git repo to existing EB environment

The way I ended up doing this was: 1) Download AWSDevTools from http://aws.amazon.com/developertools/AWS-Elastic-Beanstalk/6752709412171743 2) Move to your git repo on the CLI 3) Run /Downloads/elasticbeanstalk-cli/AWSDevTools/ [Linux or Windows] /AWSDevTools-RepositorySetup.sh EDIT: 3a) git aws.config 4) Enter AWS Access Key, AWS Secret Key, AWS Region, and enter the existing name of your AWS Application and AWS Environment. 5) Now you can git add, git commit as usual, and use git aws.push to push to your EB environment 7) You can follow the steps above to add other environments. For example if you had production and staging environments, and then use git aws.push --environment to use the same repo to push to both environments. If you come across the error The specified module 'AWSDevTools' was not loaded on Windows, this is most likely because the AWSDevTools module is not at C:\Users\ USER \Documents\WindowsPowerShell\AWSDevTools\AWSDev

Address already in use - bind(2) for 127.0.0.1:3000

you need use kill -9 4343 (use lsof -wni tcp:3000 to see which process used 3000 port and get the process pid)

Find places close by a route using Google Maps API V3 and RouteBoxer

<div id="google_map" class="google_map" style="width: 750px; height: 500px;"></div> <script src="//maps.googleapis.com/maps/api/js?v=3.2&amp;sensor=false"></script> <script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/routeboxer/src/RouteBoxer.js"></script> <script type="text/javascript">   //placing a marker on the map function createMarker(map, coords, title) {  var marker = new google.maps.Marker({   position: coords,   map: map,   title: title,   draggable: false  });  return marker; } //Search places having coordinates inside the boxes function findPlaces(boxes) {  var data = "";  for (var i = 0; i < boxes.length; i++) {   //form the query string that will be sent via ajax   if (data != "") {    data += "&";   }   data += "boxes[]=" + boxes[i].getNorthEast().lat() + ":" + boxes[i].getNorthEast().l

disable inherited_resources in ruby on rails

Solution 1 config . app_generators . scaffold_controller = :scaffold_controller Solution 2 config . generators do | g | g . scaffold_controller "scaffold_controller" end Solution 3 To force rails to use the normal scaffold generator, add -c=scaffold_generator to the end of the command

Could not find generator 'refinery:engine'

First run "gem install refinerycms" Then add the following gem then problem will be resolve gem 'refinerycms',      '~> 3.0.0.dev', git: 'https://github.com/refinery/refinerycms.git' gem 'refinerycms-i18n', '~> 3.0.0.dev', git: 'https://github.com/refinery/refinerycms-i18n.git' Then run rails generate refinery:cms --fresh-installation

create our own gem in ruby on rails

$ gem install bundler     $ bundle gem dogeify   This will create following directories   $ tree dogeify dogeify ├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── dogeify.gemspec └── lib    ├── dogeify    │   └── version.rb    └── dogeify.rb         Let's first look at the gemspec file ( dogeify.gemspec in this case).    # coding: utf-8 lib = File .expand_path( '../lib' , __FILE_ _ ) $LOAD_PATH .unshift(lib) unless $LOAD_PATH . include ?(lib) require 'dogeify/version' Gem::Specification .new do |spec| spec.name = "dogeify" spec.version = Dogeify::VERSION spec.authors = [ "Matt Huggins" ] spec.email = [ "matt.huggins@gmail.com" ] spec.description = %q{Convert everyday boring English into doge speak!} spec.summary = %q{English to doge translations} spec.homepage = "" spec.license = "MIT" spec.files

List all countries with code

[       {:name => 'Åland Islands', :iso_code => 'AX'},       {:name => 'Albania', :iso_code => 'AL'},       {:name => 'Algeria', :iso_code => 'DZ'},       {:name => 'American Samoa', :iso_code => 'AS'},       {:name => 'Andorra', :iso_code => 'AD'},       {:name => 'Angola', :iso_code => 'AO'},       {:name => 'Anguilla', :iso_code => 'AI'},       {:name => 'Antarctica', :iso_code => 'AQ'},       {:name => 'Antigua and Barbuda', :iso_code => 'AG'},       {:name => 'Argentina', :iso_code => 'AR'},       {:name => 'Armenia', :iso_code => 'AM'},       {:name => 'Aruba', :iso_code => 'AW'},       {:name => 'Australia', :iso_code => 'AU'},       {:name => 'Austria', :iso_code => 'AT'},