Saturday, June 3, 2017

How to make Bitbucket repository working with GitHub Desktop App

Source Tree is the desktop application that is available for Windows and Mac OS to work with Bitbucket repositories.

This tutorial will guide you to use GitHub Desktop application to work with Bitbucket repositories.

Bitbucket repositories are not directly supported by GitHub desktop application. You can’t clone or sync directly to or from bitbucket. Here are few steps that you need to do manually before syncing the Bitbucket repositories.

1) Copy the repository URL from Bitbucket.


Bitbucket with Github

2) Clone bitbucket repository on your local machine using command

       
git clone repository_url

Above command will ask password for your bitbucket account. Provide the password but nothing will get printed on screen even the stars for security reason.

Bitbucket with Github

3) Now add cloned repository to Github desktop application by clicking on the + button. Choose the repository that you have cloned in the first step and click “Add repository” button.

Bitbucket with Github

4) Cloned repository has been added to the Github desktop application, you can see that in the left panel under Other section.

5) Now you can execute all other GitHub commands like commit, pull, push and other commands.

Reference

https://gist.github.com/glueckpress/c53f3a07779ce7f67fe2

Friday, June 2, 2017

Lexical Scope

Scope is the area or location within the program where a variable or function is accessible.

Lexical also called static Scoping defines how variable names are resolved in nested functions: inner functions contain the scope of parent functions even if the parent function has returned.


 var scope = "I am global scope";

 function whatismyscope(){
    var scope = "I am local scope";
    
    function getScope() { return scope; }
    
    return getScope;
 }

 whatismyscope()() 


The above code will return "I am local scope". It will not return "I am a global". Because the function getScope () counts where is was originally defined which is under the scope of function whatismyscope.

It will not bother from whatever it is being called (the global scope/from within another function even), that's why global scope value I am global will not be printed.


IBM defines it as:


The portion of a program or segment unit in which a declaration applies. An identifier declared in a routine is known within that routine and within all nested routines. If a nested routine declares an item with the same name, the outer item is not available in the nested routine.



For more detail: 

http://stackoverflow.com/questions/1047454/what-is-lexical-scope
http://pierrespring.com/2010/05/11/function-scope-and-lexical-scoping/

Thursday, April 13, 2017

How to get saved password in browser

Sometimes we have saved password on different websites. You can see the User Name but Password is in dots.

how to get saved password in browser
In HTML language, User Name is visible because its type is text and Password field is in dots because of type password.

Now to see the password you need to change its type. 

What how can we change that as we don't have the code? :(

No worries, there is a way to change its type on the UI to solve our purpose.

Steps :-


1) Inspect the password field by pressing the Ctrl + Shift + C or by pressing the simply F12 button and click on Inspect button.

2) Now hover/click the cursor on the password box.

How to get saved password in browser

3) As you hover the cursor and click on the password field it will show like above image.

4) Now as you can see in the opened console window the selected code is the password field. 

5) Check its type="password".

6) Double click on the type and it will be in edit mode. Now delete the "password" from type property. It will become  type="".

7) Password is visible now :)

How to get saved password

Monday, January 23, 2017

Schematron

A language for making assertions about the presence or absence of patterns in XML documents. 


Use of Schematron

  • Busines rule validation
  • Data reporting and general validation
  • Quality control and constraints checking
  • Naming and design rule validation

How it works?


1) Find useful context nodes in the document based on XPath

2) Check to see of some other XPath expressions are true for each of those contexts

3) The report which asserts has failed.


Main Elements


schematron components


1) Schema: Schema of the Schematron


<?xml version="1.0" encoding="utf-8"?>}}
<sch:schema xmlns="http://purl.oclc.org/dsdl/schematron"
      xmlns:sch="http://purl.oclc.org/dsdl/schematron"
      xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
      xmlns:ef="http://www.efatura.gov.tr/envelope-namespace">

2) ns (namespace): Element to provide namespace and prefix


<sch:ns uri="your_schema_url" prefix="art" />

3) Pattern : section under different rules for a context are defined


<sch:pattern name="Only two paragraph tag">
  <sch:rule context="art:html/art:body/art:div[1]">
     <sch:assert test="count(//q:p) &lt;=2">Only two p tags</sch:assert>
  </sch:rule>
 </sch:pattern>

4) Rule : context is defined under which assertions are verified


<sch:rule context="art:html/art:body/art:div[1]">
   <sch:assert test="count(//q:p) &lt;=2">Only two p tags</sch:assert>
</sch:rule>

5) Assert: show failed asserts


<sch:assert test="count(//q:p) &lt;=2">Only two p tags</sch:assert>

6) Report : show passed rules


<sch:report test="not(count(//q:p) &lt;=2)">Only two p tags</sch:report>

Schematron Implementation


There are many implementations for Schematron. Probatron is one of these and below is the link to download the jar file or source code

https://code.google.com/archive/p/schematron/downloads


how schematron implementation works

Example


Following example will use Probatron.jar to verify business rule of XML.

Xml to test : candidate_doc.xml


<artist xmlns="your_schema_url" id="123">
    <body class="clear">
       <div>
          <p>
            <t>Adele -Pop Singer</t>
          </p>
          <p>
            <t>Hello</t>
          </p>
          <p>
            <t>Set fire to the rain</t>
          </p>
        </div>
    </body>
</artist>


Schematrn doc : schemaron_validation_doc.sch



<?
xml version="1.0" encoding="utf-8"?>
<sch:schema xmlns="http://purl.oclc.org/dsdl/schematron"
      xmlns:sch="http://purl.oclc.org/dsdl/schematron"
      xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
      xmlns:ef="http://www.efatura.gov.tr/envelope-namespace">

  <sch:ns uri="your_schema_url" prefix="art" />

  <sch:pattern name="Only two paragraph tag">
     <sch:rule context="art:html/art:body/art:div[1]">
        <sch:assert test="count(//q:p) &lt;=2">Only two p tags</sch:assert>
     </sch:rule>
  </sch:pattern>
</sch:schema>


Java Code: Driver.java


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;

import org.probatron.Session;
import org.probatron.ValidationReport;

public class Driver {
 static String fixArg(String arg) {
  // user concession, if no URL scheme assume these are files
  return arg.indexOf(":") == -1 ? "file:" + arg : arg;
 }

 public static void main(String[] args) {
  Session theSession = new Session();
  OutputStream os=null;
  try {
   os = new FileOutputStream("report.xml");
  } catch (FileNotFoundException e1) {
   e1.printStackTrace();
  }
  String candidate = fixArg( "candidate_doc.xml" );
  theSession.setSchemaDoc( fixArg("schematron_validation_doc.sch" ));
  try {
   ValidationReport vr = theSession.doValidation(candidate);
   byte[] data = vr.reportAsBytes();
   String strData = new String(data);
   vr.streamOut(os); // to print in file
   vr.sreamOut(System.out); // to print on console
  } catch (MalformedURLException e) {
   e.printStackTrace();
  }
  System.out.println("Done");
 }
}


Output : report.xml


<?xml version="1.0" standalone="yes"?>

<svrl:schematron-output title="" schemaVersion=""      xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
<svrl:ns-prefix-in-attribute-values prefix="q" uri="your_schema_url">
</svrl:ns-prefix-in-attribute-values>

  <svrl:failed-assert test="count(//p) &lt;=2"         location="/html[1]/body[1]/div[1]" line="4" col="22">
      <svrl:text>Only two p tags</svrl:text>
  </svrl:failed-assert>
</svrl:schematron-output>

References:


Official WebSite:

Thursday, January 19, 2017

Download video from Facebook

Sometimes we watch videos on facebook and want to download it on phone/laptop. But facebook does not provide the download link to download the video on your device.

This post will guide you how to download the video from facebook.

1) Play the video that you want to download.


Download video from Facebook

2) Right click on the video, it will show the option to "Show video URL".

Download video from Facebook

3) On click of "Show video URL," it will show the video URL on the video. Copy it.


Download video from Facebook

4) Now open http://www.fbdown.net/ and paste the copied URL to the download input box as shown in below image.


Download video from Facebook

5) On Click of download button, it will show the option to download the video in "Normal Quality" or "HD Quality".



Download video from Facebook

6) If you have installed any adblocker then you have to disable it to get the download link.


Here is the video tutorial 
https://www.youtube.com/watch?v=qO0WAv0c7oo

Wednesday, January 18, 2017

Print India map using C language

C is very powerful language even you can create your own OS in C like Unix. This post is not about to create new OS but the India’s map using C language. You will be glad just few lines of code can create India’s map.

#include <stdio.h>
main()
{
    int a,b,c;
    int count = 1;
    for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
    TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
    UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
    NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
    HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
    T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
    Hq!WFs XDt!" [b+++21]; )
    for(; a-- > 64 ; )
    putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
    return 0;
}

And here is the output

India map using c - array151

How it works?


The long string is simply a binary sequence converted to ASCII. The first for statement makes bstart out at 10, and the [b+++21] after the string yields 31. Treating the string as an array, offset 31 is the start of the "real" data in the string (the second line in the code sample you provided). The rest of the code simply loops through the bit sequence, converting the 1's and 0's to !'s and whitespace and printing one character at a time.

Tuesday, January 10, 2017

How to stylize console logging in browser

console.log() method logs any string to console window of the browser. But you know, there is a way to provide style to string message even we can draw images ;) like in facebook prints in console window

facebook styled console log message

Here is console.log signature
 console.log(msg [, subst1, ..., substN]);
The first parameter is the message that you want to print in the console and the second parameter is the array of format style properties like font-color,font-size etc. This gives you additional control over the format of the output.

So to print the message like Facebook does. Here is the code

console.log("%cStop!", "color: red; font-family: sans-serif; font-size: 4.5em; font-weight: bolder; text-shadow: #000 1px 1px;");
Even we can draw images like this
(function(url) {
  // Create a new `Image` instance
  var image = new Image();
  image.onload = function() {
    // Inside here we already have the dimensions of the loaded image
    var style = [
      // Hacky way of forcing image's viewport using `font-size` and `line-height`
      'font-size: 1px;',
      'line-height: ' + this.height + 'px;',
      // Hacky way of forcing a middle/center anchor point for the image
      'padding: ' + this.height * .5 + 'px ' + this.width * .5 + 'px;',
      // Set image dimensions
      'background-size: ' + this.width + 'px ' + this.height + 'px;',
      // Set image URL
      'background: url('+ url +');'
     ].join(' ');
     console.log('%c', style);
  };
  // Actually loads the image
  image.src = url;
})('https://i.cloudup.com/Zqeq2GhGjt-3000x3000.jpeg');
The above code will draw image in the console like this

image in console window of browser

For more detail on console.log

https://developer.mozilla.org/en-US/docs/Web/API/Console/log