Blog

How to run linux commands on windows

    1. Cygwin is a Unix-like environment and command-line interface for Microsoft Windows.
      Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment.
      Thus it is possible to launch Windows applications from the Cygwin environment, as well as to use Cygwin tools and applications within the Windows operating context.

      Official Site: https://www.cygwin.com/

       

    2. git bash is a shell where: the running process is sh.exe (packaged with msysgit, as share/WinGit/Git Bash.vbs)
      git is a known command$HOME is defined

      Official Site: https://git-scm.com/

  • How to install cygwin on Windows

How to enable ssh login to windows using cygwin

rsync on windows os

rsync: Failed to exec ssh: No such file or directory(2) on windows

nstalling cwrsync, you are likely to get this error  when you try to run this sample command from the command line.

rsync  -avz  -e  ssh ycsoftware@google.com:/home/ycsoftware /cygdrive/z/ycsoftware/

“rsync: Failed to exec ssh: No such file or directory(2)” cwrsync

The reason you are getting this is because for some reason rsync is not able to find the path to the ssh.exe file. You should change it to something like this:

C:/cygwin64/bin/rsync.exe -ar . /cygdrive/c/xampp/htdocs/test2/

Ref: http://ycsoftware.net/rsync-failed-to-exec-ssh-no-such-file-or-directory2-on-windows/

Angular 4 http post with php

Component or Service:

let data = {'title': 'foo',	'body': 'bar', 'userId': 1};
    this.http.post('http://localhost/angular4/angcrud/add_student_action.php', data)
      .subscribe(
        (res:Response) => {
          console.log(res.json());
        },
        err => {
          console.log("Error occured");
        }
      );

 

Php Script:

<?php


$postdata = file_get_contents("php://input");
$request = json_decode($postdata);

header('Content-type: application/json');
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Headers: X-Requested-With, content-type, access-control-allow-origin, access-control-allow-methods, access-control-allow-headers');
//$res_ar = array("foo"=> $_REQUEST['body']);


echo json_encode($request);

?>


<form #studentForm = "ngForm" (ngSubmit)="addStudentRecord(studentForm.value)">
  First name:<br>
  <input type="text" name="firstname" value="Mickey" ngModel>
  <br>
  Last name:<br>
  <input type="text" name="lastname" value="Mouse" ngModel>
  <br><br>
  <input type="submit" value="Submit">
</form>

 

Angular 4 Deployment

Use any of the commands:

  1. ng build
  2. ng build –prod
  3. ng build –prod –base-href /directory-name/sub-directory-name/

Create testing branch on github

  1. add normal git repository
  2. git branch gh-pages
  3. git push -u origin gh-pages

To push on the git repository

  1. git init
  2. git add origin
  3. git add .
  4. git commit -m “Initial Commit”
  5. git push -u origin master
  6. ng build –prod –base-href https://whateveruser.github.io/whateverprojectrepo/
  7. ngh

ng build –prod –base-href https://github.com/whateveruser/whateverprojectrepo/

Ref:

  1. https://www.youtube.com/watch?v=nxV3weqMzYo

.htaccess for production site

RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]

 

OOPS

  1. Design a class Rectangle
    data members[box title=”” bg_color=”#dbdbdb” align=”left”]length
    breadth[/box]member functions/methods[box title=”” bg_color=”#dbdbdb” align=”left”]setDimension()
    area()
    perimeter()[/box]
  2. Design a class Worker
    data members[box title=”” bg_color=”#dbdbdb” align=”left”]wages
    wdays[/box]member function / method[box title=”” bg_color=”#dbdbdb” align=”left”]setData()
    payment()[/box]
  3. Design a class Box
    data members[box title=”” bg_color=”#dbdbdb” align=”left”]length
    breadth
    height[/box]member functions / methods[box title=”” bg_color=”#dbdbdb” align=”left”]setDimension()
    volume()[/box]
  4. Design a class Rectangle (only for Java / C++)
    data members[box title=”” bg_color=”#dbdbdb” align=”left”]length
    breadth[/box] member functions / methods[box title=”” bg_color=”#dbdbdb” align=”left”]setDimension()
    area()
    perimeter()[/box]It must overload setDimension() method twice:
    1. by passing 1 argument
    2. by passing 2 arguments

  5. Design a class Box (only for Java / C++)
    data members[box title=”” bg_color=”#dbdbdb” align=”left”]length
    breadth
    height[/box] member functions / methods [box title=”” bg_color=”#dbdbdb” align=”left”]volume()[/box] It must contain 3 constructors
    1. 1 parameter
    2. 2 parameter
    3. 3 paramter
  6. Design a class Account
    data members [box title=”” bg_color=”#dbdbdb” align=”left”]balance[/box]member functions / methods [box title=”” bg_color=”#dbdbdb” align=”left”] deposit(amt)
    withdraw(amt)
    showBalance()[/box]
  7. Design a class Set
    data members [box title=”” bg_color=”#dbdbdb” align=”left”]3 numbers[/box] member functions / methods [box title=”” bg_color=”#dbdbdb” align=”left”] SUM()
    MEAN()
    MAX()
    MIN() [/box]
  8. Design a class Student
    data members [box title=”” bg_color=”#dbdbdb” align=”left”]roll_number
    name [/box] member functions / methods [box title=”” bg_color=”#dbdbdb” align=”left”] setData()
    getData() [/box]
  9. Design a class Account
    data members [box title=”” bg_color=”#dbdbdb” align=”left”] balance
    interest_rate [/box] interest_rate must be shared by all objects (static modifier) and its default value 10.25 [box title=”” bg_color=”#dbdbdb” align=”left”] interest(no_of_years) [/box]
  10. Design a class Student
    data members [box title=”” bg_color=”#dbdbdb” align=”left”] roll_number
    name [/box] member functions / methods [box title=”” bg_color=”#dbdbdb” align=”left”] setData()
    getData() [/box]
  11. Design a class Account
    [box title=”” bg_color=”#dbdbdb” align=”left”] account_number
    balance
    interest_rate [/box] member functions / methods [box title=”” bg_color=”#dbdbdb” align=”left”] interest(no_of_years) [/box]
  12. Design a class Student
    data members [box title=”” bg_color=”#dbdbdb” align=”left”] roll_number
    name [/box] member function / methods [box title=”” bg_color=”#dbdbdb” align=”left”] getData() [/box] roll_number must be automatically generated.It also keep track of total number of Students.

  13. Design a package MyCircle and MyRectangle (Only for Java)
    [box title=”” bg_color=”#dbdbdb” align=”left”] radius
    length
    breadth [/box] member functions / methods: [box title=”” bg_color=”#dbdbdb” align=”left”] area()
    circumference()
    perimeter() [/box]
  14. Design a class Student
    data members [box title=”” bg_color=”#dbdbdb” align=”left”] roll_number
    name [/box] member functions / methods [box title=”” bg_color=”#dbdbdb” align=”left”] getData()
    showData() [/box] Create 5 objects of Student using Array

  15. Design a class Student and List ClassRoom
    add list of Students in ClassRoom
    display List

  16. Design a class Account and List Bank
    add list of Account in Bank
    display List

  17. Create array of Student Objects
    data members [box title=”” bg_color=”#dbdbdb” align=”left”] roll_no
    name
    college [/box] member functions / methods [box title=”” bg_color=”#dbdbdb” align=”left”] readData()
    showData() [/box]
  18. Create a class RBI (Only for Java)
    data members [box title=”” bg_color=”#dbdbdb” align=”left”] balance [/box] member functions [box title=”” bg_color=”#dbdbdb” align=”left”] RBI()
    deposit(int amt)
    withdraw(int amt)
    showBalance() [/box]

Array to CSV in Java

 

package com.demo;

import java.io.IOException;
import com.csvreader.CsvWriter;

public class ArrayToCSVDemo {

  public static void main(String[] args) {
    
    String array[] = {"Suryanagar, Vikhroli", "Java", "SQL", "13"};
    
    try {
      
      CsvWriter writer = new CsvWriter("awesomefile.csv");
      
      writer.writeRecord(array);
      
      writer.close();
      
    } catch (IOException e) {

      e.printStackTrace();
    }
    
  }

}

Reference Link: http://www.journaldev.com/12014/opencsv-csvreader-csvwriter-example

Jar File: http://www.java2s.com/Code/Jar/j/Downloadjavacsvjar.htm

Using FileWriter class

import java.io.FileWriter;

public class TestFileWriter {

  public static String implodeString(String[] split) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < split.length; i++) {			
        sb.append(split[i]);
        if (i != split.length - 1) {
            sb.append("\",\"");
        }
    }
    return "\"" . concat(sb.toString()) .concat("\"");
  }
  
  public static void main(String[] args) {
    
    String array[] = {"Suryanagar, Vikhroli", "Java", "SQL", "13"};
    
    try {
      
      FileWriter fw = new FileWriter("testout.csv");
      //fw.write("\"Suryanagar, Vikhroli\", Java, SQL, 13");
      fw.write(implodeString(array));
      fw.close();
    } catch (Exception e) {
      System.out.println(e);
    }

    System.out.println("Success...");

  }

}

 

 

Hello World django

Here are simple steps to create hello world web application in python using django framework

  1. Step 1: Install virtual environment and create virtual environment for your project
    pip install virtualenvwrapper-win
    
    mkvirtualenv myproject
  2. pip install virtualenv
  3. virtualenv name_to_your_env
    
  4. name_to_your_env\Scripts\activate
  5. After activation 
    
    $ django-admin.py startproject HelloWorld  $ cd HelloWorld 
    $ ls HelloWorld manage.py
  6. $ python manage.py runserver 
    Validating models... 
    0 errors found ... 
    Django version 1.6.5, using settings 'HelloWorld.settings' 
    Starting development server at http://127.0.0.1:8000/ 
    Quit the server with CONTROL-C.
  7. $ django-admin startapp HelloWorldApp
    $ ls
    HelloWorld HelloWorldApp manage.py
  8. edit settings.py under HelloWorld project directory
    # Application definition
    INSTALLED_APPS = ( ‘django.contrib.admin’,
    ‘django.contrib.auth’,
    ‘django.contrib.contenttypes’,
    ‘django.contrib.sessions’,
    ‘django.contrib.messages’,
    ‘django.contrib.staticfiles’,
    ‘HelloWorldApp’, )
  9. modify the urls.py which is under the project directory, HelloWorld
    from django.conf.urls import patterns, include, url 
    from HelloWorldApp.views import foo 
    
    #from django.contrib import admin 
    #admin.autodiscover() 
    
    urlpatterns = patterns('', 
    # Examples: 
    # url(r'^$', 'HelloWorld.views.home', name='home'), 
    # url(r'^blog/', include('blog.urls')), 
    #url(r'^admin/', include(admin.site.urls)), 
    url(r'HelloWorldApp/$', foo), 
    )
  10. modify views.py under app directory, HelloWorldApp
    # Create your views here. 
    from django.http import HttpResponse 
    def foo(request): 
        return HttpResponse("Hello World!")
  11. Run the server
    python manage.py runserver

     

  12. Hit this URL on browser
    http://localhost:8000/HelloWorldApp/

 

Ref Links:

  • https://docs.djangoproject.com/en/1.11/howto/windows/
  • http://www.bogotobogo.com/python/Django/Python_Django_hello_world.php
  • https://stackoverflow.com/questions/18684231/python-setup-command-not-found
  • https://stackoverflow.com/questions/8074955/cannot-import-name-patterns
  • https://scotch.io/tutorials/build-your-first-python-and-django-application
  • http://jinja.pocoo.org/docs/2.10/templates/