Startup Landing Pages with Firebase

Now-a-days Landing Page has become common and popular among startups and publishers. Every landing page has one important call-to-action, i.e. to sign up early adopters for their beta version.

To get up & running as soon as possible, the simplest and fastest way to build a landing page is basically having it as a static site without any back end. The downside of this approach is, we need to figure out a way to store the emails that are signed up. As you would expect, there are quite a few really good services you can use right of the bat.

Some of the above services even provides HTML templates, A/B testing and much more. For a non-developer these sites would be the best fit.

If you know a bit of web development and want to build you own custom landing page, then I would strongly recommend to use Firebase to not only collect emails but even feedbacks. Firebase provides powerful APIs to store and sync data in realtime.

Going forward I will show you the technical part of how you can build the pages in Firebase.

Firebase Email Storage

Once you have created a firebase account and have logged in, create a firebase application.

You need to include the firebase javascript in your landing page. This provides the functionality to save your data (e.g. email) into your firebase application.

<script src="https://cdn.firebase.com/js/client/1.0.18/firebase.js"></script>

Email Signup Form

Following is a basic HTML template for email sign up form.

<div class="signup">
    <h2 class="signup-title">Sign up for beta</h2>
    <p id="signup-success" class="text-success"></p>
    <p id="signup-error" class="text-danger"></p>
    <form class="signup-form form-inline" id="signup-form" role="form" onsubmit="return signup(this)">
        <input class="form-control" name="email" type="email" placeholder="Your email. eg., joe@acme.com" required>
        <button class="btn btn-success" id="signup-button" type="submit" >Join now</button>
    </form>
</div>
Firebase script to save email addresses

On the submission of the button, the script script is invoked to store the email address into your firebase application.

<script>
    var signupForm = document.getElementById('signup-form');
    var signupSuccess = document.getElementById('signup-success');
    var signupError = document.getElementById('signup-error');
    var signupBtn = document.getElementById('signup-button');
    var onSignupComplete = function(error) {
      signupBtn.disabled = false;
      if (error) {
        signupError.innerHTML = 'Sorry. Could not signup.';
      } else {
        signupSuccess.innerHTML = 'Thanks for signing up!';
        // hide the form
        signupForm.style.display = 'none';
      }
    };
    function signup(formObj) {
        // Store emails to firebase
        var myFirebaseRef = new Firebase("https://yourappname.firebaseio.com/signups");
        myFirebaseRef.push({
          email: formObj.email.value,
        }, onSignupComplete);
        signupBtn.disabled = true;
        return false;
    }
</script>

Contact messages

You can also store the feedback, suggestions and questions into your firebase application.

Following is the basic HTML template for a contact form.

<div class="contact">
    <h2 class="contact-title">Send us a message</h2>
    <p id="contact-success" class="text-success lead"></p>
    <p id="contact-error" class="text-danger lead"></p>
    <form class="contact-form" id="contact-form" role="form" onsubmit="return sendMessage(this)">
        <input class="form-control" name="name" type="text" placeholder="Your name. eg., Joe" required>
        <input class="form-control" name="email" type="email" placeholder="Your email. eg., joe@acme.com" required>
        <textarea class="form-control" name="message" placeholder="Your message for us" rows="5" required></textarea>
        <br />
        <button class="btn btn-success pull-right" id="send-button" type="submit" >Send Message</button>
    </form>
</div>

On submission, the below script is invoked to save your email address along with the message into your firebase application.

<script>
    // Send message
    var contactFrom = document.getElementById('contact-form');
    var contactSuccess = document.getElementById('contact-success');
    var contactError = document.getElementById('contact-error');
    var sendBtn = document.getElementById('send-button');
    var onMessageComplete = function(error) {
      sendBtn.disabled = false;
      if (error) {
        contactError.innerHTML = 'Sorry. Could not send message.';
      } else {
        contactSuccess.innerHTML = "Message has been sent.";
        // hide the form
        contactFrom.style.display = 'none';
      }
    };
    function sendMessage(formObj) {
        // Store emails to firebase
        var myFirebaseRef = new Firebase("https://yourappname.firebaseio.com/messages");
        myFirebaseRef.push({
          name: formObj.name.value,
          email: formObj.email.value,
          message: formObj.message.value
        }, onMessageComplete);
        sendBtn.disabled = true;
        return false;
    }
</script>

It is one of the simplest way to handle forms in your landing page. Firebase provides 100 MB of data storage in their basic free plan, which they have aptly named it as Hacker Plan. This should be sufficient for startups to store email addresses and messages.

Caution: If someone gets your firebase URL, they can certainly spam you. Anyway, that is not something you would be worrying about in evaluating your startup idea.

Please share your thoughts and suggestions. Have a nice day.

View comments

Commands and Options I Wish I Knew Earlier About Git

Git becomes de facto of source code management (SCM) system among developers. Many developers used to work on git from console. Mostly used commands are git status, git add, git commit and git push.

Apart from these commands, there are lot of useful commands in git. Initial days, I find difficulties in tracking changes made by me and my team mates couple of days or few weeks ago. Here we will see some of commands that are interesting and useful to your workflow.

1. Short status output

git status is mostly used command in Git. But it gives lot of information which is not useful for people who are proficient with git. If you are one among them, then use

git status -sb

2. View changes by revision

If you want to view changes made at particular revision

  git show <revision>

  git show df2edcd
  (or)
  git show HEAD     #HEAD means latest commit
  (or)
  git show HEAD~1   #HEAD~1 means commit before the commit that HEAD currently points at

In case, you want to view only changed file name, not the contents, Use --name-only option

  git show --name-only  df2edcd
  (or)
  git show --name-only --oneline df2edcd
  (or)
  git show --name-only  --pretty="format:" df2edcd

3. View changes of specific file

If you want to view changes of specific file, then

  git show df2edcd:app/index.html
  (or)
  git show HEAD~1:app/index.html

  git show @{22-09-2014}:app/index.html

4. Search for commit message

You want to search a commit which message matches a regex

  git show :/fixed
  # shows the last commit which has the word "fixed" in its message

  git show :/analytics
  # shows the last commit which has the word "analytics" in its message

5. list all files that were modified or added in this time

List all files added/modified 9 days ago

  git diff "@{9 days ago}"
  git diff --name-only "@{9 days ago}"
  git diff --name-status "@{9 days ago}"

List all files added/modified between 9 days ago and 6 days ago

  git diff "@{9 days ago}" "@{6 days ago}"
  git diff --name-only "@{9 days ago}" "@{6 days ago}"
  git diff --name-status "@{9 days ago}" "@{6 days ago}"

6. Changes between two commit revision

List all files between two commits adab4ab and 6da161b

  git diff adab4ab^ 6da161b
  git diff --name-only adab4ab^ 6da161b
  git diff --name-status adab4ab^ 6da161b

Hope it useful. Share your favorite commands in comments. Happy commit and have a nice day.

View comments

Fix Shellshock Bash Vulnerability in OSX Bash

GNU Bash vulnerability, referred to as Shellshock or the Bash Bug, was found on Sep 24, 2014. The Shellshock vulnerability is very widespread and even more so than the OpenSSL Heartbleed bug So it is highly recommended that affected systems are properly updated to fix or mitigate the vulnerability as soon as possible.

What is Shellshock

GNU Bash through 4.3 processes trailing strings after function definitions in the values of environment variables, which allows remote attackers to execute arbitrary code via a crafted environment, as demonstrated by vectors involving the ForceCommand feature in OpenSSH sshd, the mod_cgi and mod_cgid modules in the Apache HTTP Server, scripts executed by unspecified DHCP clients, and other situations in which setting the environment occurs across a privilege boundary from Bash execution.

To know more about Shellshock, read an amazing article from Troy Hunt

Check System Vulnerability

You can check the system for Shellshock vulnerability by running following command in bash

env Y='() { :;}; echo I am vulnerable!' bash -c "echo This is Bash"

If your version of Bash is vulnerable, then you will see following output

I am vulnerable
This is Bash

Instead of echo I am vulnerable! portion, attacker can run any command; arbitrary code following a function definition within an environment variable assignment. If your system don't have Shellshock vulnerability, then you will see following output

bash: warning: Y: ignoring function definition attempt
bash: error importing function definition for `Y'
This is Bash

How to fix in Mac OSX

If your bash is vulnerable, then you can install latest version of bash as follows, provided that you have XCode installed,

$ mkdir bash-fix
$ cd bash-fix
$ curl https://opensource.apple.com/tarballs/bash/bash-92.tar.gz | tar zxf -
$ cd bash-92/bash-3.2
$ curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-052 | patch -p0
$ curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-053 | patch -p0
$ cd ..
$ sudo xcodebuild
$ sudo cp /bin/bash /bin/bash.old
$ sudo cp /bin/sh /bin/sh.old
$ build/Release/bash --version # GNU bash, version 3.2.53(1)-release
$ build/Release/sh --version   # GNU bash, version 3.2.53(1)-release
$ sudo cp build/Release/bash /bin
$ sudo cp build/Release/sh /bin

Once you installed, check your bash version(bash --version), it should be GNU bash, version 3.2.53(1)-release

For security reason, you have to remove the executable permission from older bash

$ sudo chmod a-x /bin/bash.old /bin/sh.old

That's it. Keep in mind that this fix is temporary. We have to wait for real fix until apple releases it.

If you using Linux distribution, please read Digital Ocean blog on Shellshock

Kudos

View comments