Monday 9 December 2013

HTML5 FileReader api

HTML5  FileReader api

FileReader

Event fired:               . 
  onload << fired after  reading all file content into the memory.
  onprogress << file reading progress
  onabort << If file reading is aborted
  onerror << problem reading file. Errors could be : File not found, readable error, and file reading aborted

Tuesday 22 October 2013

SDLC: Best of every model

SDLC

Agile, extreme, scrum , waterfall, RAD, kanban etc etc. I won't put any benchmark and won't try to map in good or bad category. Infact, I'd pull the gist from each and would put it on the screen So, that next time when i stuck anywhere I can see the solution .

Chaos theory: It's made by people who were more concern about testing and fixing bugs. So, they made this model. They gist of this model is :  Fix the most important bug right away.

Extreme Programming: YAGNI: You not gonna need it. Implement features which are going to be used by end users. Don't waste time implemention something that's going to be used in future.

Agile: Batch by batch. Keep the batch small and keep processing them till all batch process or final product is ready.

Scrum: Keep the process agile with the help of scrum master and regular meetings.

Kanban: Keep the size of bath in Agile controlled.



Other philosphical notes notes i like are:
         DRY: Do not repeat yourself
         KISS: Keep it simple, stupid .

Saturday 5 October 2013

Multiple File Upload :Laravel4










Issues and their resolutions with multiple file load

  1. var_dump( Input::file("file_field") ) == NULL, for multiple file uploading but works fine for one file.
    1. Check if you have max_upload_file and max_post_size set very low in php.ini file
  2. Input::file("file_field") is giving only one file object.
    1. Verify that you have  file filed set with name attribute containing brackets . eg. Form::file("file_name[]") .
  3. If you're doing some image processing you then might need to extend memory_limit.
    ini_set('memory_limit', '64M'); >> Set it to ini_set('memory_limit', -1)     
log.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 1xxxxxx bytes)' in ...\vendor\filp\whoops\src\Whoops\Handler\PrettyPageHandler.php:123
Stack trace:
Error  Say's that you need to increase memory for your application. Where? In php.ini file.
If you don't have access? then increase dynamically using ini_set()

     4.  Consult your laravel log file if you face any other error . Log file you may find inside storage/log folder.
eg. path/to/your/application/app/storage/logs





Sunday 30 June 2013

Starting php with Laravel4 : Getting Started

It is been a long time since i last used php. If i remember correctly, I used php around 2 year and 6 months back. Since them am fiddling with RoR and java with struts, hibernate , and scala with play.

It's a reminiscence for me.

Ok, lets start with php5 with laravel.

Setup:
  1. Install apache
    1. create config file
    2. enable rewrite module, if not
 Installing apache and php5

sudo apt-get install apache2 php5

Once, apache2 is installed, move to next step of creating a site.
Here is the template of site look like:

<VirtualHost *:80>
    # Host that will serve this project.
    ServerName app.dev
    # The location of our projects public directory.
    DocumentRoot /path/to/our/public
    # Useful logs for debug.
    CustomLog /path/to/access.log common
    ErrorLog /path/to/error.log
    # Rewrites for pretty URLs, better not to rely on .htaccess.
    <Directory /path/to/our/public>
        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
        </IfModule>
    </Directory>
</VirtualHost>
Edit it to suit laravel project directory. Replace "/path/to/our/public" with the path to public folder inside laravel project dir.
Now, put this site inside /etc/apach2/site-available
Enable site:
a2ensite site_name
 Enable rewrite module
a2enmod rewrite
Reload apache2
sudo service apache2 reload
Restart apache2
sudo service apache2 restart
Now, you may see your site at following destination

http://localhost

 Now,  lets edit /app/routes.php file and add our "hello world" route

Route::get('/hello', function() {
     return 'Hello world!';
});



Point your browser to :  http://localhost/hello

 


happy coding.. ;)
==============================

Issue:
   Routes not working?
   Solution:  Please verify you have 'rewrite' module enable.  If it's enabled then verify you have write permission to laravel project dir and it's subfolder.
If it's still not working, then google is your friend. 


Reference:
  1.  laravel site config: https://github.com/daylerees/laravel-website-configs 
  2. Routes not working? http://stackoverflow.com/questions/12045881/php-laravel-routing-issue

Wednesday 26 June 2013

openSSH, generating passwd file

First generate Group:
On local system:
            mkgroup -l >> ..\etc\group

On system with user organized in domains
            mkgroup -d >> ..\etc\group

And then password:
                On local:
            mkpasswd -l -u username >> ..\etc\passwd
NOTE: the username specified above must be an existing windows login account.
               
                On system with many domains:
            mkpasswd -u smm08030 -d mycorp >> >> ..\etc\group




NOTE:
If your computer sees multiple domains, you may have to specify the domain
name that the user "qhander" is part of to mkpasswd after the -d flag
(i.e., run "mkpasswd -u YourUser -d YourDomain >> /etc/passwd").
You also need to run "mkgroup -d >> /etc/group" (and, apparently,
"mkgroup -d YourDomain >> /etc/group")...  Also, you most likely have
*two* users with the name "qhander": one local to your machine (with a
small user id), and one in the domain (with UID 18544) -- you log in as
the domain one, but your /etc/passwd contains the local one (with the
wrong SID and UID).  Once you update /etc/passwd with your domain user
information, change the name of the local user to something else (e.g.,

"qhander_local").

Tuesday 11 June 2013

When to use try{}Catch{}?

A system that swallows and masks exceptions isn’t a healthy system.

I'll remember this line whenever i need to put try/catch block in my line as a thumb rule . :)

Saturday 20 April 2013

ROR installation through RVM, along with passenger

Assumption:
I assume you have apache2 installed and working on your system/server.

Installtion instruction:
  1. Install rvm
  2. Install ruby with rvm and then install gems: Rails
  3. Install Passenger and passenger apache module
  4. Configure apache2
  5. Learn to create virtualhost settings for your every rails application

Installation of RVM and Ruby

Install rvm with ruby

Saturday 13 April 2013

Rails Validators


Validators in Rails 3:



How to build Custom validators in Rails 3?



def validate 
  errors.add_to_base "If you are attaching an image you must enter a title for it" if         
  !upload_image.blank? and image_label.blank? 
end 

Note: add_to_base is deprecated in Rails 3 and you'll get "undefined method add_to_base ".   So, instead use :

        errors[:field_name] << "Error Message"

Form Fields in Rails



form_for         :


<%= f.select :menu_id, options_from_collection_for_select(@menus, 'id', 'name') %>
<%= f.datetime_select  :schedule , :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}%>


form_tag         :


<%= form_tag :controller => "index", :action => "index" do %>
<%= select_tag(:area_id, options_from_collection_for_select(@areas, :id, :area_name, @area_id),
 :onchange => "this.form.submit()") %>
<% end %>


OR
Over an integer range:
<%= f.select :field_name, (1..50) %>  OR select("product", "quantity", 1..100)


<form accept-charset="UTF-8" action="/area/2" method="post">
    <select id="area_id" name="area_id" onchange="this.form.submit()">
      <option value="1">Japan</option>
      <option value="2" selected="selected">Thailand</option>
      <option value="3">USA</option>
      <option value="4">Canada</option>
      <option value="5">England</option>
    </select>
</form>



:Value parameter

Error sometime occur: undefined method 'merge' for  xxx:xxx

Solution: use ":value" parameter


<%= f.hidden_field :session_id,  :value => "abcdefg0123456789" -%>


:MULTIPLE parameter
When you need to send an array of information back
<%= f.hidden_field "orders", :multiple => true,  :value=>schedule.id %>

Install php5 and mysql powered by nginx

Trouble shooting Rails



Errors:

------------------------------------------
------------------------------------------
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.
rb:2:in `require': Incorrect MySQL client library version! This gem was compiled
 for 6.0.0 but the client library is 5.5.16. (RuntimeError)
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/m
ysql2/mysql2.rb:2:in `<top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/m
ysql2.rb:9:in `require'
....

Solution:
   change 'mysql' version accordingly. Newer('older') version of mysql gem might have installed.

As in my case it's 0.3.x installed .  I changed it to 0.2.x and now my app is running perfectly.

In gem file, make following changes:

                     '0.2.gem 'mysql2', '0.2.6'

------------------------------------------
------------------------------------------

root@m1:/var/www/production# heroku keys:add
/usr/local/lib/ruby/1.8/x86_64-linux/readline.so: libreadline.so.5: cannot open shared object file: No such file or directory - /usr/local/lib/ruby/1.8/x86_64-linux/readline.so (LoadError)
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55:in `require'
        from /usr/local/lib/ruby/gems/1.8/gems/heroku-2.32.14/lib/heroku/command/run.rb:1
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55:in `gem_original_require'
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55:in `require'
        from /usr/local/lib/ruby/gems/1.8/gems/heroku-2.32.14/lib/heroku/command.rb:14:in `load'
        from /usr/local/lib/ruby/gems/1.8/gems/heroku-2.32.14/lib/heroku/command.rb:13:in `each'
        from /usr/local/lib/ruby/gems/1.8/gems/heroku-2.32.14/lib/heroku/command.rb:13:in `load'
        from /usr/local/lib/ruby/gems/1.8/gems/heroku-2.32.14/lib/heroku/cli.rb:27:in `start'
        from /usr/local/lib/ruby/gems/1.8/gems/heroku-2.32.14/bin/heroku:17
        from /usr/local/bin/heroku:23:in `load'
        from /usr/local/bin/heroku:23

Solution:
  $ apt-get install libreadline-ruby1.8

understand recursion

In my school days i was afraid of a thing called Recursion. For me it works like a magick. I never try to take recursion problem head on and worked on them. Instead i take shelter to conditional loop and for few years it worked fine, untill i faced one problem.

Problem was specific to my job but to put it simple it was a problem of traversing a tree and to tell generate its  position matrix.


            A
          /     \
       B        C
      /   \       /  \
    D    E   F    G

Problem:  List down all the node along with their relative position to Root 'A'
eg.
A:  0  (Assume A's position as 0 :root)
B : 0 0
C: 0 0 1
D: 0 0 1  .




There is wonderful Article about recursion on stackoverflow. I strongly recommend it for those who want to see the real logic behind this magick. 

http://stackoverflow.com/questions/717725/understanding-recursion

Rails Task: Creation and deployment

Rails does have one very interesting module, besides dozens of other : RAKE

Rake help you write task and then you can use it to write schedulers or database maintenance script or anything, as per your requirement.
I used it to write one cron job.
Here is how i made one rake task.

$ rails generate task   namespace_name taskName_one taskName_two
 ==> It will generate file with the name  namespace_name.rake and in there it will define two methods
with the name "taskName_one" and "taskName_two".