Saturday, November 21, 2015

Introduction of FOOTERLABS fun club in HEADERLABS

I have no doubt to state that start-ups are best place to work because they develop a NEVER GIVE UP attitude in you. In start-ups every morning new challenges are waiting for you. At the end of day you don't realize how time passes.

After all these happenings, in the end of day your mind got tired and you require some refreshment for it. Some like music, reading but i personally like sports. So i talked with some of my colleagues to start a sports in the evening. I am stun by the response everyone says LETS DO IT. On the same day we finalize the everything and give the name FOOTERLABS(because game is all about the movement of foot).

First problem is which sports and where. we decided Badminton and in GMC (Municipal Corporation of Gurgoan) park in front of our office building. We put light, mark the ground and now we are playing for around 2 hrs and we all the completely refresh for more work.

We are planing to organize single and double player tournament every month to keep our motto up.

Sports are best thing to keep to stay fit, healthy, active. In last i would like to state that don't think too much and as nike logo says JUST DO IT.

Friday, October 30, 2015

Filepicker.io run the sucess function twice

I am using filepicker.io to upload the file in my rails application. What i am doing is first upload the file to s3 using filepicker.io, after successfully upload post the data to my server. i Am doing all these by binding a click event through jquery.

$('a.upload_file').off('click').on('click', function (event) {
     filepicker.setKey('MY FILEPICKER KEY');
     filepicker.pickAndStore({extensions: '.pdf'},
            {location: 'S3'},
            function (uploadedObjects) {
                // send request to server 
            },
            function (FPError) {
                console.log(FPError.toString());
            }
        );
    })
 
 
As in rails turbolink comes into picture which not request for javascript.
i will start calling the pickandstore function twice.
 
what i did wasremove the set key from the function it fix the issue. 

Tuesday, May 26, 2015

irb introduction

Interactive Ruby or irb is an interactive programming environment that comes with Ruby. 

Usage Syntax:

To invoke it, type irb at a shell or command prompt, and begin entering Ruby statements and expressions. Use exit or quit to exit irb.

$ irb[.rb] [options] [programfile] [arguments]

Here is a complete list of options:

-f                              Suppress reading of the file ~/.irbrc.
-m                             bc mode (load mathn library so fractions or matrix are available).
-d                              Set $DEBUG to true (same as ruby -d).
-r                               load-module Same as ruby -r.
-I                               path Specify $LOAD_PATH directory.
--inspect                   Use inspect for output (default except for bc mode).
--noinspect               Don't use inspect for output.
--readline                 Use Readline extension module.
--noreadline             Don't use Readline extension module.
--prompt                   prompt-mode (--prompt-mode prompt-mode) Switch prompt mode.

                                 Predefined prompt modes are default, simple, xmp, and inf-ruby.
--inf-ruby-mode         Use prompt appropriate for inf-ruby-mode on Emacs. Suppresses --readline.
--simple-prompt        Simple prompt mode.
--noprompt                No prompt mode.
--tracer                      Display trace for each execution of commands.
--back-trace-limit n    Display backtrace top n and tail n. The default value is 16.
--irb_debug n             Set internal debug level to n (not for popular use).
-v(--version).             Print the version of irb.




































Friday, April 24, 2015

Basics before writing a jquery plugin


Jquery Basics


Take a look at this code:  

$( "a" ).css( "color", "red" );

This is some pretty basic jQuery code, but do you know what's happening behind the scenes? Whenever you use the $ function to select elements,
it returns a jQuery object. This object contains all of the methods you've been using (.css(), .click(), etc.) and all of the elements that fit your selector.
The jQuery object gets these methods from the $.fn object. This object contains all of the jQuery object methods, and if we want to write our own methods, it will need to contain those as well.


Write your first jquery plugin


Let's say we want to create a plugin that makes text within a set of retrieved elements green. All we have to do is add a function called greenify to $.fn and it will be available just like any other jQuery object method.

$.fn.greenify = function() {

    this.css( "color", "green" );

};

$( "a" ).greenify(); // Makes all the links green.



Notice that to use .css(), another method, we use this, not $( this ).
This is because our greenify function is a part of the same object as .css().

for more detail refer JQUERY

Friday, February 6, 2015

Intercom.io with Rails

My rails project requirement to provide the support to end users, so that we can do the communication with end users in real time. I also wants to track the active users and slipping users and also want ask feedback.

So i decided to integrate intercom.io. It is paid service but i want to launch my site as soon as possible and track and communicate with my customers, take their inputs to improve my product.

Integration of intercom is just a matter of 2 mins job in rail. you just have to intercom-rails gem and thats it.

Friday, January 30, 2015

Upload file directly to amazone s3 bucket using html and javascript

My requirements is to upload the assets to s3 bucket. One approach is to upload file to my server and then to amazon s3, but my application deals in big file in that case it blocks my process which i don't want. Second approach i can upload directly to amazon s3 bucket in this case i can save my asset block.

I work on rails so code snippet reflects ruby but its an easy you can do in any language

Variables

AWS-BUCKET-NAME - name of the bucket in which you want to upload.
AWSAccessKeyId - Aws access key of your account.
PATH - where you want to upload file(its your logic to generate dynamic value, i used ruby SecureRandom.uuid).
REDIRECTPATH - where amazon sends the response with uploaded file path and bucket name.
Policy - it is base64 encoded policy i will explain later.
Signature - it is base64 encoded signature

HTML Code for form

AWS-BUCKET-NAME
.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
  PATH">
  AWSAccessKeyId">
 
  REDIRECTPATH">
  Policy
">
  Signature">
 
 

  File to upload to S3:
 
 

 

Policy - it a base64 encoded string which contain the policy. Policy just nothing but the cross verification of the form field value(other than AWSAccessKeyId, policy and signature fields). you 3 options starts_with, exact match and range

sample policy is
example(Its ruby code but you can easy understand it) :-
def generate_encoded_policy
policy_document = {expiration: "2029-01-01T00:00:00Z",
        conditions: [
        {bucket:
AWS-BUCKET-NAME},
        ["starts-with", "$key", key_base_name],
        {acl: "private"},
        {success_action_redirect:
REDIRECTPATH},
        ["starts-with", "$Content-Type", "application/pdf"],
        ["content-length-range", 0, 104857600]
    ]
    }.to_json

    Base64.encode64(policy_document).gsub("\n","")

end 

it is a ruby function which return me the BASE64 encoded string

Signature - It is also the base64 encoded signature
example:-
def generate_signature
       Base64.encode64(
        OpenSSL::HMAC.digest(
            OpenSSL::Digest::Digest.new('sha1'),
            AWSSECRETKEY, generate_encoded_policy)
    ).gsub("\n","")
  end


for more detail refer http://aws.amazon.com/articles/1434