Posts

Fresh Server Setup with Nginx, Passenger and Rails

Whenever you get a fresh server to setup it takes too much time to setup everything and sometimes you miss the essential task to perform on the server so for that this blog can help you. Once you are done with the creating the EC2 instance you'll get a pem file using that file login to the server. Login to server: chmod 400 /path_to_pem/you_pem_file_name.pem ssh -i /path_to_pem/you_pem_file_name.pem username @ec2-some_ip_seperated_by_(-)_(-).compute-1.amazonaws.com Note: username is the name of root user for ubuntu machine it “ubuntu” and for AMI(Amazon Machine Instances) is “ec2”. If you are successfully logged in to the server please do the followings: Add user(deploy) Now you need to add a user deploy in the server for deployment sudo -i export EDITOR=vim echo "export EDITOR=vim" >/etc/profile.d/editor.sh apt-get update useradd -d /home/deploy -m deploy passwd deploy apt-get install vim visudo deploy ALL=(ALL:ALL) ALL su deploy

Upload a file in S3 without any form

Uploading a file in S3 is a normal scenario but all I got is uploading the file using a form but what if I want it to upload it without any form. There are very simple steps to upload a file or object in S3 without any form. def s3_resource @s3 = Aws :: S3 :: Resource .new( region : ENV [ 'aws_region' ]) end def s3_bucket s3_resource @s3 .bucket( ENV [ 'aws_bucket' ]) end def upload_file_to_s3 ( file ) s3_resource file_name = File .basename( file ) obj = @s3 .bucket( ENV [ 'aws_bucket' ]).object( 'certificates/' + file_name ) obj .upload_file( file ) end As you can see these methods The first method s3_resource   is just creating a instance of your S3. The second method s3_bucket is initializing your bucket. Now the third one upload_file_to_s3(file) basically uploads your file in S3. In the third method In the first line initiating the s3_resource. In the second line fetching the file_name which can be abc.txt because

SAML IdP initiated SSO Resources Rails

I have been searching a lot for this to implement SAML IdP initiated SSO in Rails. Firstly what I found several resources on it for rails they are very few: 1.) ruby-saml   gem is to implement Service Provider in SAML. 2.) saml_idp gem is to implementing SAML IdP using  but this gem does not provide the way to implement IdP initiated SSO it is for SP initiated SSO. 3.) libsaml which provides the core functionality in SAML IdP but found very hard to implement SAML IdP initiated SSO because @benoist the owner of this gem does not documented it properly even all gems provided for SAML doest not have a proper documentatio. 4.) Another gem is saml_tool which actually provides the way to generate metadata and assertion for SAML request and response. 5.) And Yes, there was a great example for saml idp which saml_tools_demo which describes the use of saml_tools gem. Using Saml_idp and saml_tool gem I finally implemented SAML IdP initiated SSO. And I have described the way

Uploading profile pic using photofy gem

Hi fellas, Photofy gem is to provide simple method to do fileupload of pictures and provides getter setter methods of it and save on model object commit we are used of using paperclip and other gems. But it saves your effort from active record and other kind of stuffs. Include gem photofy in your Gem file. gem 'photofy' bundle install define photofy with the config in the model for which you want the file upload photofy(:avatar_image, {image_processor: Proc.new {|img| img.scale(200,200)}}) here after that you need to define your file upload attribute as: <%= f.file_field :avatar_image %> in the form where you want to upload the file after that in your action please whitelist your avatar_image attribute as: params.require(:users).permit(:name, :avatar_image)  Please be assure you have rmagick gem and imagemagick installed in your system. After uploading pic and submitting the form you will see a photofy folder will be created in app directory but

Integration of angular 2 tour of heroes with rails 5 api

Image
Hi fellas I know its been a hard journey of angular 2 tour of heroes but now once you are done with tour of heroes you may want it to integrate with Rails 5 api only application and to achieve that first you need a separate rails 5 api only application I have wrote a blog for rails 5 with hero resource just follow that and create a basic rails 5 api app with hero resource. http://nitanshu.blogspot.in/2016/08/initialization-of-rails-5-api-only.html In the json you see created_at and updated_at keys it will cause problems on the Angular 2 end since our app is only expecting the id and name attributes. Let’s take care of that right now since we’re already working on the Rails side. We’ll need to add the active_model_serializers gem to our Gemfile . gem 'active_model_serializers' bundle install mkdir app/serializers Create a new file called app/serializers/hero_serializer.rb with the following content. class HeroSerializer < ActiveModel::Serializer   att

Basic app in Rails 5 api mode

Image
  In Rails 5  you can create an app which will provide you only JSON API support. To do that actually there are two ways one is through rails gem and another is from git repo of rails I prefer rails gem: ================= First way(preferable) ================== To start with rails you need ruby version >=2.2.2 so first you need to install ruby-2.3.0 and rails 5 rvm install ruby-2.3.0 rvm use --default ruby-2.3.0 gem install rails -v 5.0.0 rails new my_app --api cd my_app rvm use 2.3.0 create a rvm wrapper for your application for that create two files one is .ruby-version and another is .ruby-gemset. In .ruby-version file type the current ruby version ruby-2.3.0 In .ruby-gemset file type the current ruby version @my_app now to initialize rvm wrapper cd .. cd - rvm current now you will see ruby-2.3.0@my_app bundle install ===================== Second way ===================== git clone https : / / github .com / rails / rails cd rails bundle in

Angular 2 basic terminologies

Transpiler : A source-to-source compiler, transcompiler or transpiler is a type of compiler that takes the source code of a program written in one programming language as its input and produces the equivalent source code in another programming language.   Decorator : Decorators are a proposed standard for ECMAScript 2016 by Yehuda Katz, to annotate and modify classes and properties at design time. This sounds pretty much like what annotations do right? Well… sort of. Let’s take a look at what a decorator looks like: // A simple decorator @ decoratorExpression class MyClass { } Wait. This looks exactly like an AtScript annotation! That’s right. But it isn’t. From a consumer perspective, a decorator indeed looks like the thing that we know as “AtScript Annotation”. There is a significant difference though. We are in charge of what our decorator does to our code. Taking the code above, a corresponding decorator implementation for @decoratorExpression cou