Best way to add chained any_of in Rails

If you are using Mongoid and suppose you have two scopes like class Post     ….     scope :scope1, -> {any_of([{field1: value1},{field2: value2}])}     scope :scope2, -> {any_of([{field3: value3},{field4: value4}])} … end Now if you are executing Post.scope1.scope2 you are expecting posts which have (field1 == value1 or field2 == value2) and (field3 == value3 or field4 == value4) But mongoid will return result like (field1 == value1 or field2 … Continue reading Best way to add chained any_of in Rails

Rule for AWS S3 Bucket Naming

  The name of the bucket should not contain any period in between. For example: The bucket name should not be something like: mybucket.mydomain.com Although it would not give any error while you are testing in development environment with a development bucket like: mybucket.development.mydomain.com but it would create a problem with the bucket which you would make for you production mode. So, the name of … Continue reading Rule for AWS S3 Bucket Naming

Five Simple Steps to Upload file directly to S3 in Reactjs

For Direct file uploading to s3 using  React, you need to do following 5 steps, We will update CORS configuration for AWS S3. Generate policy and signature. Retrieve policy and signature using ajax call.  upload file using React form Ajax Request For Direct File Upload to s3 1. AWS S3 Setup: Sign in to the AWS console and select the S3 section. Select or create … Continue reading Five Simple Steps to Upload file directly to S3 in Reactjs

Submitting your website to Alexa, DMOZ, Google and Bing for better SEO

Adding your website on various Search Engines(e.g. Bing, Google) and Directories(e.g. Alexa, DMOZ) is very important for good SEO(Search Engine Optimization). Search Engine have become a very popular way for people to send their site to various search engine and directory as this is a great way to get traffic from search engine. Getting listed in  these search engines and directories is one of the … Continue reading Submitting your website to Alexa, DMOZ, Google and Bing for better SEO

Protect Email Harvesting in Rails Application

Q. What is E- mail Harvesting? Email harvesting is the process of obtaining lists of email addresses using various methods for use in bulk email or other purposes usually grouped as spam. We need to hide our emails from these email harvesters. There are methods to hide email addresses from page source to minimise visibility against the email harvesting spam bots. Each method has some advantages as … Continue reading Protect Email Harvesting in Rails Application

Nginx setting for securing your Web Application

1. Block Exploits, SQL Injections, File Injections, Spam, User Agents, Etc. Thanks to Falko Timme for his blog. You need to add following code in your server block. server { […] ## Block SQL injections set $block_sql_injections 0; if ($query_string ~ “union.*select.*\(“) { set $block_sql_injections 1; } if ($query_string ~ “union.*all.*select.*”) { set $block_sql_injections 1; } if ($query_string ~ “concat.*\(“) { set $block_sql_injections 1; } … Continue reading Nginx setting for securing your Web Application

4 Ways to Ensure Security in Rails Application

1. Basic authentication password should not be stored in source code. Example: authenticate_or_request_with_http_basic do |username, password| username == “example” && password == “example” end This warning will be raised if http_basic_authenticate_with is used and the password is found to be a string (i.e., stored somewhere in the code). Password and username can be stored in environment variables. authenticate_or_request_with_http_basic do |username, password| username == ENV[“my_app_user”] && … Continue reading 4 Ways to Ensure Security in Rails Application

Uncaught Invariant Violation: ReactDOM.render(): Invalid component element

Problem: Uncaught Invariant Violation: ReactDOM.render(): Invalid component element: This may be caused by unintentionally loading two independent copies of React Solution: Check if you are loading react through package.json and also loading React in index.html. If so remove it from one place. Check you have node_modules folder in react-dom folder, if so check inside node_modules you have new react v14.0. react-dom@0.14.0 node_modules\react-dom └── react@0.14.0 (envify@3.4.0, … Continue reading Uncaught Invariant Violation: ReactDOM.render(): Invalid component element

MaxPostPreDataLengthExceededError

Error: I’m trying direct fileupload to S3 with an html form and received  following xml code in response, <Error> <Code>MaxPostPreDataLengthExceeded</Code> <Message>Your POST request fields preceeding the upload file was too large </Message> <MaxPostPreDataLengthBytes>20480</MaxPostPreDataLengthBytes>  <RequestId>E1F68A5B755E4498</RequestId> <HostId>+8gIUdxr7i0ISyrlpDjDK+wZajKLDIng1945PGaQs2CwDNHVV+XQesPJ+fn4GtWdBB8NWBJLsdo=</HostId> </Error>   Reason: make sure the file upload element is named file? If the element is named anything other than file, you’re likely to receive a MaxPostPreDataLengthExceededError response. <input type=”file” … Continue reading MaxPostPreDataLengthExceededError

Show Progress of Long Task Using sidekiq and pusher

PURPOSE: With the increasing expectation of web-applications, everyone wants real time updates or real time notifications to improve the web portals user experience. Understandably, my project required Real time notifications too. The aim is Notify the user using Web notifications. We are going to use sidekiq gem (for background process. This is required if we have a long process.) pusher api (for sending notification about the the process running in … Continue reading Show Progress of Long Task Using sidekiq and pusher