Category Archives: Uncategorized

zsh: command not found: bundle error

I have installed zsh in my ubuntu 16.04, but after install rails when trying to bundle install I found following error in my console:

zsh: command not found: bundle (after gem install bundle)

After searching on google I found following solution from stackoverflow.com:

  • echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.zshenv
  • echo ‘eval “$(rbenv init -)”‘ >> ~/.zshenv
  • echo ‘source $HOME/.zshenv’ >> ~/.zshrc
  • exec $SHELL

Running all those commands one by one will solve this problem.

Selecting series in a datframe

We know pandas have a most common data structure which is data-frame. We can select some values from a data-frame with some basic commands.

import pandas as pd
ufo = pd.read_table('http://bit.ly/uforeports', sep=',')

or we can use read_csv() method which have a comma separator by default.

ufo = pd.read_csv ('http://bit.ly/uforeports')

ufo.head()
City Colors Reported Shape Reported State Time
0 Ithaca NaN TRIANGLE NY 6/1/1930 22:00
1 Willingboro NaN OTHER NJ 6/30/1930 20:00
2 Holyoke NaN OVAL CO 2/15/1931 14:00
3 Abilene NaN DISK KS 6/1/1931 13:00
4 New York Worlds Fair NaN LIGHT NY 4/18/1933 19:00

We can select a series with bracket notation

ufo['City']
0                      Ithaca
1                 Willingboro
2                     Holyoke
3                     Abilene
4        New York Worlds Fair
5                 Valley City

]
We can also concatenate two column with simple python operation.

ufo['City'] +', '+ ufo['State']
0                      Ithaca, NY
1                 Willingboro, NJ
2                     Holyoke, CO
3                     Abilene, KS
4        New York Worlds Fair, NY
5                 Valley City, ND

 

Prevent browser page caching

One of my rails application shows problem about browser caching. After destroying all login session page redirect back me to my home page. But when I click my browser back button I still see the login pages.

Here is few solution for that.

Clear Cache/No-Cache :

// Code disables caching by browser. Hence the back browser button
// grayed out and could not causes the Page_Load event to fire
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore(); </pre><p><strong> Use Meta Tag for No-Cache: </strong></p><pre>&lt;meta Http-Equiv="Cache-Control" Content="no-cache"&gt;
&lt;meta Http-Equiv="Pragma" Content="no-cache"&gt;
&lt;meta Http-Equiv="Expires" Content="0"&gt;

Clears Browser History and Redirects URL:

//clears browser history and redirects url
&lt;SCRIPT LANGUAGE="javascript"&gt;
{
     var Backlen=history.length;
     history.go(-Backlen);
     window.location.href=page url
}
&lt;/SCRIPT&gt;

Rails :

Write this code on application controller.

before_filter :set_cache_buster

  def set_cache_buster
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
  end