Friday, January 14, 2011

Interesting PHP functions : ini_get/get_cfg_var/getenv; memory_get_peak_usage

If not tried before, try using ini_get to get the configuration variables.
Use case:
 You do not want to change your php.ini file for open_basedir restrictions, then just get the configuration value using ini_get and then you can set it using ini_set

To  enable and disable or change the error_reporting values on a given page use:
error_reporting(8183);   at the top
error_reporting(get_cfg_var('error_reporting'));at the bottom [gets orginial value, not the set value].

get_cfg_var returns the value from php.ini directly,while the ini_get returns   the runtime config value


getenvGets the value of an environment variable
 

Monday, December 6, 2010

Getting rid of control characters from mail

http://www.math.iitb.ac.in/~srg/LaTeX/howto.html

use global substitution
:g/cntrl-v cntrl-m/s// /g

Checking memory

try sar(system activity reporting), it is a good alternative to top. My rhel box was having i/o wait which I could find using sar.

sar 1 200
Other commands : free (-m) tells you the total memory, memory used for cache etc.

Wednesday, October 27, 2010

Python

Issue 1: python ImportError No module named


Resolve 1: The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later.

Sunday, September 26, 2010

Shell

To remove duplicates in your .bash_history file, export this variable in the .bashrc file:
HISTCONTROL=erasedups

To increase the .bash_history size from 500 to 1000 commands, export this variable in the .bashrc file:
HISTSIZE=1000


alias hs='history | grep $1' 

Wednesday, July 14, 2010

Few interview questions.


Q1) Factorial of a large num ?
The main difficulty in computing factorials is the size of the result.


Constant Limit = 1000;           %Sufficient digits.
Constant Base = 10;              %The base of the simulated arithmetic.
Constant FactorialLimit = 365;   %Target number to solve, 365!
Array digit[1:Limit] of integer; %The big number.
Integer carry,d;                 %Assistants during multiplication.
Integer last,i;                  %Indices to the big number's digits.
Array text[1:Limit] of character;%Scratchpad for the output.
Constant tdigit[0:9] of character = ["0","1","2","3","4","5","6","7","8","9"];
BEGIN
 digit:=0;                       %Clear the whole array.
 digit[1]:=1;                    %The big number starts with 1,
 last:=1;                        %Its highest-order digit is number 1.
 for n:=1 to FactorialLimit do   %Step through producing 1!, 2!, 3!, 4!, etc. 
  carry:=0;                      %Start a multiply by n.
  for i:=1 to last do            %Step along every digit.
   d:=digit[i]*n + carry;        %The classic multiply.
   digit[i]:=d mod Base;         %The low-order digit of the result.
   carry:=d div Base;            %The carry to the next digit.
  next i;
  while carry > 0                %Store the carry in the big number.            
   if last >= Limit then croak('Overflow!'); %If possible!
   last:=last + 1;               %One more digit.
   digit[last]:=carry mod Base;  %Placed.
   carry:=carry div Base;        %The carry reduced.
  Wend                           %With n > base, maybe > 1 digit extra.
  text:=" ";                     %Now prepare the output.
  for i:=1 to last do            %Translate from binary to text.
   text[Limit - i + 1]:=tdigit[digit[i]]; %Reversing the order.
  next i;                        %Arabic numerals put the low order last.
  Print text," = ",n,"!";        %Print the result!
 next n;                         %On to the next factorial up.
END;