Python Basics in Less Than 128 Words

In python everything is object. An object is a piece of code that is characterized by:

  • Data
  • Methods: These are mechanisms for manipulating data

Creating the object

A character chain object is created in the space of objects via the character 'or '.

Method calls are made via a point:

'hello'.upper()

A variable name allows you to store a reference to the object:

counter 1

The variable called object 1 reference counter

In python the variable name contains letters and numbers but cannot start with a number. A good practice is to give a good variable name.

Example:

ma_variable 5

Dereference:

ma_variable - 'HELLO'

Python is strong typing language, the type is related to the object and not to the variable.

del ma_variable

The del control removes the variable from the space of the variables. If the object no longer has a reference, a mechanism for the release of memory is activated: the garbage collector.

The Python language in less than 128 words

Python is a programming language that is characterized by:

  • its readability: The syntax of language is based on presentation (importance of indentation)
  • Pragmatic: The goal is to make effective programs that contain as few lines of code as possible.

It is also easy to access, so you can easily exchange with other programmers.

The first version of python dates from 1994, Python 3 dates from 2008. The language is stable as older versions of the language continue to be maintained (updated).

Python is portable, it works on most platforms (mobile, PC, MAC, Linux …), there are many bookstores available.

Python is under PSF license, the debate on evolution is democratic and is subject to the creator of the language Guido Van Rossum.

Hamiltonian cycle in a Graph in less than 128 words

A Hamiltonian cycle is a cycle that contains all the tops of the graph.

There is no general algorithm (i.e. valid for any graph) and effective (i.e. no algorithm in the number of computational steps or a polynome the size of the graph) to find out if there is a Hamiltonian cycle in a graph.

Hamiltonian cycle source wikipedia

DIRAC Condition: If for all the tops u of the graph G degree (u) 'n /2 then G contains a Hamiltonian cycle

ORE Condition: If for any pair u and v of non-neighbors deg(u) 'deg(v) 'then G contains a Hamiltorian cycle

If a graph verifies diraC's condition then it verifies the orE condition (the reciprocal is false).

Coupling in a Graph in less than 128 words

A coupling is a set of ridges two to two independent: they do not share peaks.

Example of coupling in a graph: the 2 red stops do not share peaks (2 to 2 independent)

Perfect coupling: Each top of the graph is in exactly one stop of coupling

Example of perfect coupling in a graph

A perfect graph has an even number of peaks (the reciprocal is not true)

A perfect coupling is a coupling of maximum size (impossible to enlarge, you can not pair more), the reciprocal is not true.

Example of maximum coupling but no max size (i.e. it is possible to do for example a coupling with 3 stops)

Example of use: In a logistics company, employees have one or more permits allowing them to drive a certain type of vehicle. The problem can be represented in a graph with the company's employees and vehicles as its top. To solve the problem you then have to find a pairing of max size.

Gluttonous algorithm to find maximum coupling:

Step 1: A stop is randomly selected and stored in a copy of the graph (left)

Selecting the stop

Step 2: Stop stops that are incidental at both summits are removed and another stop is selected randomly

Step 3: Stop stops that are incidental at both peaks are removed, resulting in maximum coupling

Google AMP on WordPress in less than 128 words

Google AMP is a publishing technology that allows you to create web pages that load almost instantly on mobile phones.

You need to create another version of your site that meets amp project standards. Once you've done this, your AMP site will have its own URL (votresite.com/page/amp) and will be compatible with web browsers such as Chrome, FireFox and Safari.

To set up my wordpress site I went into Extensions – Add and I typed the keyword "AMP" I install
ed and activated the official AMP extension released by AMP Project Contributors (more info on the plugin here: https://fr.wordpress.org/plugins/amp/)

In the AMP-General tab you can set up how the plugin works:

The plug-in can be configured to follow one of three different model modes: Standard, Transitional and Reader.

In standard mode, you use AMP as a frame for your site and there is no need to create separate AMP and non-AMP versions.

In Reader and Transition modes, a given page will have a canonical URL and a corresponding (paired) AMP URL. The AMP plugin does not serve as a mobile theme; it does not redirect mobile devices to the AMP version. Instead, the AMP version is presented to mobile visitors when they find content on platforms such as Twitter, Pinterest, Google Search and others.

Reader mode only supports AMP delivery for posts, pages and other types of publishing, while Standard and Transition modes support the entire site in AMP format.

The Web explained in less than 128 words

The Internet is a computer network, the Web is a network of information that are connected by hypertext.

The web server provides information when asked: queries that are made by web customers.

The browser allows you to view the information, it sends an HTTP query over the internet.

The search engine responds with a list of urls. Web pages contain HTML describes the structure and content of the document. The CSS style sheet contains the shape of the code.

The browser interprets HTML and CSS and the user-readable poster. The search engine robots are called "spiders" and they browse the web pages and their links: they do website crawling.

The PageRank algorithm in Python

PageRank is an algorithm used by Google Search to rank websites in their search engine results. PageRank is a way to measure the importance of website pages.

This is not the only algorithm used by Google to order search engine results, but it is the first algorithm used by the company it is best known.

The PageRank of a page is calculated from the sum of the PageRank of pages with a link entering the calculated page that is divided by the number of outgoing pages of the page, a mitigating factor is applied to symbolize the probability that The user surfs another page.

I install networkx, it is a Python package for the creation, manipulation and study of structure, dynamics and complex network functions.

Networkx provides data structures and methods for storing graphs that I use for the pagerank algorithm.

import networkx as nx
import numpy as np

graphe-nx. DiGraph()

TablePages - ["A","B","C"]page rank #Exemple with 3 pages
graph.add_nodes_from (tablePages) #Ajout tops of the graph

#on adds bows, we have:
#la Page A has a link to B 
#la page B has a link to C
#la Page C has a link to B
#la page C has a link to A
Page B has 2 incoming link
Page C has an incoming link 2 links out
Page A has a link entering an outgoing link
graph.add_edges_from([('A','B'), ('C','A'),('B','C'), ('C','B')])
print ("Graphe Summits:")
print (graphe.nodes))
print ("Stop the graph:")
print (graph.edges)
#Si an attenuation factor of 0.85 'd' is considered
The page rank formula is:
#PR (1-d)/n - Sum of all pages (PR(i) of incoming links to p/number of link coming out of the page that reference p)
PR(A) - (1-0.85)/3 - 0.85 - (PR(C)/2)
PR(B) - (1-0.85)/3 - 0.85 - (PR(A)/1 - PR(C)/2)
PR(C) - (1-0.85)/3 - 0.85 - (PR(B)/1)

pagerank - nx.pagerank
print (pagerank)

Python insertion sorting in less than 128 words

Insertion sorting is a slow, stable sorting, in place (we work on the structure directly and not a copy).

The sorting by insertion is comparable to the sorting that one performs of a deck of card. 

def tri_par_insertion (table):
	#parcours of all the elements of the painting
	globalnombre_operation
	for i in range (1,len(tab)-1):
		#pour each of the elements of the table we go through the precedents and exchange
		#on back up the value of the current element
		ValueElementCurrent - table[i]
		print ("common element: " ' ' ' ' '[i] ' - index i' ' ' str(i))
		j i
		#on defines the j index and we go through the predents elements as long as it'
		while(j-0 and table[j-1]-valueElementCourant):
			#si the element traveled among the previous values is higher than the current element it is inserted in its place and one decal sades on the left
			table[j] - table[j-1]
			J - 1
			nombre_operation '1'
		#lorsqu we come out of the loop we place all the elements higher to the current element to the right of j then we must put the current element to the position j
						
	table [j]- valueElementCourant
		
nombre_operation 0
tab[3,9,6,1,2,4,7,5,8]
print ("before sorting by insertion: " - str(tab))
tri_par_insertion (tab)
print ("after sorting by insertion: " - str(tab))
print ("number of operations:" - str(nombre_operation))

Glossary on graphs in just over 128 words

source wikipedia: Unoriented graph

Graph: A set of interconnected dots

Summits (vertices, a vertex): The dots of a graph are called adjacent s
ummitsSommets (adjacent vertices): Two peaks are adjacent if they are connected to each o
ther, Edge: The link between two peaks is called an edge if the relationship between two summit is not oriented (no notion of precedence, or order in which one visits the two summits).

source wikipedia: oriented graph


Arc (arc): The oriented link between two summits (it is an arrow that indicates the meaning of the oriented relationship, there is a notion of execution order
and constraint to visit the two peaks)The degree of a vertex: Number of
edges that are start from a summit. Order of a graph: The n
umber of tops in a graph. Related graph :: A graph is related if all the tops are connected b
y any chain. Eulerian path: A chain that takes all the edges once from the graph.


Adjacent Matrix: The adjacence matrix of a graph is a matrix whose lines and columns are both indexed by the tops of the graph, with a 1 in the cell for row i and column j when the tops i and j are adjacent , and a 0 if not.

source wikipedia: adjacence matrix

CookieViz on Mac OS X in more than 128 words

CookieViz is a visualization tool that measures the impact of cookies on your own browsing.

https://linc.cnil.fr/fr/cookieviz-une-dataviz-en-temps-reel-du-tracking-de-votre-navigation

The page is git is https://github.com/LINCnil/CookieViz

I install MAMP: https://www.mamp.info/en/downloads/

MAMP is a compilation of free open source software to manage dynamic websites on computers running macOS or Windows: Apache, the web server; MySQL, the database management system; phP, Perl or Python, programming languages used for web development.

Install Homebrew: Homebrew is a free open source software management system that simplifies the installation of software on Apple's macOS and Linux operating system.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

The script asks to switch to superuser mode via the sudo command and asks to type the password several times.

At the end of the installation you get a successful installation!

I install mitmdump which is in the mitmproxy package

brew install mitmproxy

Validate the installation by tapping mitmdump –version

mitmdump --version
 Mitmproxy: 4.0.4
 Python: 3.7.5
 OpenSSL: OpenSSL 1.1.1d 10 Sep 2019
 Platform: Darwin-17.7.0-x86_64-i386-64bit

I start MAMP and not MAMP PRO which is paid

I get the home page of my Apache web server that is booted on port 8888 by default I can reach by typing localhost:8888 as url in my browser.

If I go into the MAMP -Preferences menu I can change the ports used.

I downloaded from the github source of cookieViz https://github.com/LINCnil/CookieViz via the Clone and download link. It is also possible to start a terminal and place yourself at the root of the WEB Apache server.

By default the root is in /Applications/MAMP/htdocs/ but you can change it via the MAMP graphical interface

cd /Applications/MAMP/htdocs/
git clone https://github.com/LINCnil/CookieViz.git

By default the default user of the database is "root" and password "root" To change t
he password by default: https://docume
ntation.mamp.info/en/MAMP-Mac/How-Tos/Change-the-password-of-the-MySQL-root-user/ /App
lications/MAMP/Library/bin/mysqladmin -u root -p password

Adding a user phpmyadmin – mysql – user 'add a user' tab User Accounts

I added a user 'cookvi' with password 'cookvi'

I edited the settings.inc file via a text editor or nano control

/**
 The database server used by CookieViz.
 Default is 'localhost' and should be fine for most cases.
 If 'localhost' doesn't work and the database runs locally, try '127.0.0.1'.
 */
define ('DB_SERVER', '127.0.0.1:8889');

...

define ('DB_USER', 'cookvi');

/**
 The password of the CookieViz database user.
 */
define ('DB_PASSWD', 'cookvi');

I then edited the nano monitor_mitmdump.php file of the directory /soft

cd /Applications/MAMP/htdocs/CookieViz/soft/
nano monitor_mitmdump.php 

I went to http://localhost:8888/phpmyadmin/ and I created a new CookieViz base

I clicked on the created database and i used the "import" function and loaded the file /Applications/MAMP/htdocs/CookieViz/cookieviz/sql/url_referer-1.sql which contains the table structure

Edit the four values below
$PROXY-HOST – "localhost"; Proxy server addre
ss $PROXY-PORT – "8082"; Proxy server p
ort $PROXY-USER -""; Userna
me $PROXY-PASS -""; Password

CookieViz is php5 compatible and not phpt7 you should expect changes in the code:

Replacing:

$link - mysql_connect ('localhost', '', '') by $link - mysqli_connect ('127.0.0.1:8889', 'cookvi', 'cookvi','CookieViz') 
mysql_select_db ('CookieViz') by mysqli_select_db ($link, 'CookieViz')
mysql_error() by mysqli_connect_error()
mysql_query ($query) by mysqli_query ($link, $query)
mysql_fetch_assoc ($result) by mysqli_fetch_assoc ($result) 
mysql_close ($link) by mysqli_close ($link)  

Start a server mitmdump on port 8082: mit
mdump -p 8082 -w mitmdump.log

I am now launching the php script /Applications/MAMP/htdocs/CookieViz/soft/monitor_mitmdump.php

At the firefox level I went into network preference sets in the general settings and I configured the proxy

We find that we have connections that pass through the proxy Prox
y server listening at http://:8081 127.0.0.1:
49915: clientconnect 127.0.0.1:4991
5: CONNECT www.youtube.com:443< cannot="" establis
h="" tls="" with="" client="" (sni:="" www.youtube.com):="" tlsexception("ssl="" handshake="" error:="" error()")="[(‘SSL routines’, ‘ssl3_read_bytes’, ‘sslv3 alert bad certificate’)]" 1
27.0.0.1:49917:="" clientconnect=""
127.0.0.1:49915:="" clientdisconnect=
"" 127.0.0.1:49917:="" get="" http://detectportal.firefox.com/success.tx
t="">< 200="" ok="" 8b="" 127.0
.0.1:49919:="" clientconnect="" 12
7.0.0.1:49920:="" clientconnect=""
127.0.0.1:49919:="" get="" http://detectportal.firefox.com/success.txt?ipv4=""
>< 200="" ok="" 8b="" 127.0.0.
1:49920:="" get="" http://detectportal.firefox.com/success.txt?ipv6="">< 200 O
K 8b 200="" ok=""></ 200 OK 8b>

The results can then be viewed on the web server http://localhost:8888/CookieViz/cookieviz/