All Blogs
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Kiprosh
is now part of
LawLytics
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Files uploaded on S3 are not encrypted. To make them secure, we either need to encrypt the file at client's end then upload or configure S3 settings to encrypt the files after upload. i.e Server Side Encryption. Amazon S3 Server Side Encryption (SSE) employs AES-256, an encryption standard that provides a considerably high level of protection. To allow SSE for S3, just include following code in headers while uploading file: 'x-amz-server-side-encryption' => 'AES256' To check, login to S3 and check properties of the file uploaded. The "Server Side Encryption" option under Details tab should show AES-256 radio
Consider a scenario where multiple models has 1 to N relationship with one model. For example. Consider models like School, College, Event and Semester are having multiple relationship with a single model i.e Student. It will not be a good idea to have multiple foreign keys to student model like school_id, college_id, event_id and semester_id into one table. So whenever you have a scenario like this, you have to follow polymorphic associations. For example: In your models i.e school.rb, college.rb, semester.rb and event.rb, define something like this: class School <
Pretty often we are in situation where we need to merge branches especially while using "branch per feature" pattern to push our changes to repo. You may follow these simple yet very important steps to merge your branches. Assuming that you are on "master" branch on your local repo, do this to check the branch. git branch Expected output master Checkout the branch you want to merge, example you want to merge branch "feature-devise", So do this git checkout feature-devise Expected output master feature-devise Come back on master branch to start merge process git
Here's a way to add filters to your controllers without subclassing the Devise controllers. For example, I have a prepare_something method that I want to apply as a before_filter to all of the Devise controller actions. First, create a module in config/initializers/devise_filters.rb where we’ll implement a method to add all the filters to Devise that we want. We also need to make sure this module calls this method upon initialization so that our filters get added upon startup (this is important for the production environment). # Put this somewhere it will get auto-loaded, like
ActiveRecord::Base#find_in_batches. This lets you iterate over all the records in cursor-like fashion (only retrieving a set number of records at a time into the memory): @Subscription.find_in_batches(batch_size => 100 ) { |subs| subs.each { |s| ... } }@ iterate over all subscriptions in chunks of 100 find_in_batches supports scopes @class Subscription < ActiveRecord::Base scope :expired, :conditions => { :expired => true } end @ @Subscription.expired.find_in_batches(:batch_size => 100 ) { |subs| ... }@ _Disadvantage: _ You can’t specify :order or :limit in the options. Where to use it: Large Dataset, where you need to loop through
Kaltura is an third party video implementation library. Using Kaltura we can host our videos on a dedicated server or cloud. Advantages: You can host your own CE server to store videos and create players. You can host it on cloud, which is paid as well as free, but for free you can upload less videos and you get less cuztomizations. One can secure the video by streaming the video using RTMP protocol, now the video cant be downloaded via RealPlayer or any web download means. Also the video is supported across all browsers and all devices including iOS devices.
In rspec, we need to make http call for our test to pass. In this case, we are actually making http request which is not a best practice while we are executing tests. The best way is to fake http request with the actual expected response without making actually going to that url. For faking http request in ruby, we have couple of gems namely FakeWeb and WebMock. FakeWeb: Usage: Include 'fakeweb' in your Gemfile under test group only. require it in spec helper. use it in specs Syntax: FakeWeb.register_uri(method, url, :body => "response text, html,
What is Mass Assignment? Assigning multiple attributes of a record with params received from the application within a single query. For example,{:user => {:first_name => "FirstName", :last_name => "LastName", :role => "admin"}} So while creating a new record in User table, we specify as => User.create(params[:user]) In the above query, rails gives the freedom for one-to-one mapping of params attributes with model-record attributes. Lets say, we don't explicitly specify as User.create(:first_name => params[:user][:first_name], :last_name => params[:user][:last_name].......). Such assignments
Photo by chuttersnap / Unsplash (Modified) Windows Azure, is windows based cloud service. You can deploy your code and build your apps on the cloud server. Also, it has support for all the OS and not only Windows. Also, you can setup Virtual machine and you can do a Remote desktop to that machine. Which is a nice feature? When Node.js launched it was not supporting the Windows environment. Later Microsoft brought Node.js to Windows Azure. So that Microsoft users could build and deploy Node.js apps Now we can use Node.js on Windows, we can develop and
Mechanize Mechanize - Advantages Basically mechanize is capable of navigating through the websites by logging into the site by form submission, clicking the links, maintaining session data, capturing the redirects. We can use this series of scripts to perform a desired operation in a Web application through mechanize script. Mechanize - Missing parts Right now mechanize doesn't support the javascript execution within the mechanize, So mechanize team is adding javascript support to mechanize for future versions. Workaround - We need to simulate javascript functions and calls in ruby methods and call those methods for appropriate actions. [Complete doc - Mechanize]