Basic Python Notes with examples

Python is an object-oriented programming language which is gaining popularity in building complex applications. It is used in different fields, eg create web applications, handle big data, perform complex mathematics and also considered by data scientist to analyze their problems. This page is a simple writeup of basic python notes, the code statements which are normally used in almost all the scenarios.

Squash, fixup and remove commits on GitHub

Multiple numbers of commits on a pull-request can be merged into a single commit using the squash and fixup option provided by Github. This article is to check how to merge different commits on your Github repository or remove any unwanted commits on your pull request.

Consider the following example to do this -

1. Create a local git branch on your terminal. 

$ git checkout upstream/master -b test_branch

where -

Hide Element after div is loaded dynamically

There is a normal procedure in javascript to hide any element based on page load or click event. For eg, when the page is loaded and DOM is built, using the below code snippet, a button is able to hide the element after it is clicked.

$.function($) {
  $("#button").click(function() {
    $('#div').hide();
  });
}

Similarly, an element can be hidden based on some condition when the page is loaded. Eg - consider the below snippet -

Reload parent page after AJAX modal popup is closed.

Modal popup window is more elegant way of showing information to the user in views,webform, etc. We can also insert an ajax modal popup link for a webform in a global text field of a view. When the view is rendered, the link is displayed to display the webform in an ajax dialog box, but many a times, when the webform is filled with newer values and saved on the ajax itself, the parent page, in this case, the view, is not refreshed to show the updated values in the form.

List of some useful Git Commands

Git provides a various set of commands to operate the repository on our local setup. Eg. git clone to copy the repo from the upstream, git status to check what files, etc are changed, git commit to save our changes, push and pull to update and retrieve from the upstream. Here are some other useful git commands which are mostly used by users in following cases.

Set default value for datepicker using jQuery in Drupal

Datepicker in drupal is rendered as separate select elements for day, month and year by default which makes it difficult to set a default value if we want to set it to some string value, eg. today, +2 months, etc. This page is to check how we can set default value for datepicker using a simple jQuery.

Get string from PHP

Consider you have the above string value. If you are sending this value from a php code, convert it to a date format using strtotime().

Hidden Element not submitted on Drupal Form

Hidden elements can be easily created on a Drupal form. When the form is submitted, $form_state variable seems to be holding the value of this element in various hooks, "form_alter", "validate", etc.

Note that if you have an ajax call or a jquery code which assigns or modifies the value of the hidden element, this value will not be sent when the form is submitted. For eg, An hidden element is created from -