dilluns, 22 d’octubre del 2018

Instalation

browsesync is based on node/js platform so npm install -g browser-sync

Default running

browser-sync start --server

in my case to go fast i got an alias in my bashrc

alias bserve='browser-sync start --server' then to run for me is

$ bserve --file * -w

diumenge, 14 d’octubre del 2018

GIT most used comands

GIT log and info

set alias into .bashrc vimlog

alias gitlog='git log --all --oneline --graph'

to see diferences betwen branches write .. betwen branches

git diff branch_a..branch_b

GIT Commit

when I sure git commit -m -a "message" when not it allows check the diferences git add -p

GIT branch

create a branch called features git checkout -b features merge into branch into master git checkout master to go to master and the git merge features. if there is confilcs resolve or file to file editing one by one or use git mergetool it opens a nice tool based in vimlo git checkout --theirs or git checkout --ours in case you wan take iether feture or master

GIT rebase

Use rebase when you want get all the master o shared repo to you personal branch

dilluns, 13 d’agost del 2018

Testing With Gradle

Gradle has Junit out of the box, the reporting is not still so fancy as maven but it has the same functionality

Gradle JUnit 5

testCompile('org.junit.jupiter:junit-jupiter-api:5.2.0')
testCompile('org.junit.jupiter:junit-jupiter-params:5.2.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.2.0')

to run the test just execute gradle test but if you wish and specific test ie the whole class is still posssible with gradle test --tests org.jordiesc.BlogTest

dimecres, 4 de juliol del 2018

Update Ubuntu certificates

  • create a directory into /usr/local/share/ca-certificates mkdir new directory

  • copy the certificate directory file *.crt give permsissions and chmod 644 for the files

  • sudo update-ca-certificates

Get the certificates chain from the server

openssl s_client -connect HOST:PORTNUMBER -showcerts save the files as crt.

dilluns, 26 de febrer del 2018

Threading in Python

Very very similar to Java but with less code. 

import threading
import datetime
import time

DELAY = 10

def hacertrabajo():
timeinit = datetime.datetime.now()
print("se inicia "+str(timeinit))
time.sleep(10)
print("se finaliza "+ str(datetime.datetime.now()) + "en "+str(datetime.datetime.now()-timeinit))

th1 = threading.Thread(target=hacertrabajo,name="th-1")
th2 = threading.Thread(target=hacertrabajo,name="th-2")

th1.start()
th2.start()


print("no se espera")

if you execute the prgoram you will see that the output "no se espear" is writtein even without having finisthed both threads.

PS C:\Users\jordi\Documents\python\multithread> python multi.py
se inicia 2018-02-26 22:02:26.326352
start th1
se inicia 2018-02-26 22:02:26.328306
start th2
no se espera
se finaliza 2018-02-26 22:02:36.328301en 0:00:10.001949
se finaliza 2018-02-26 22:02:36.330257en 0:00:10.001951

to wait implement the call join(seconds) where seconds are the timeout , the time point the time when the control will arive to point join

import threading
import datetime
import time

DELAY = 10

def hacertrabajo():
timeinit = datetime.datetime.now()
print("se inicia "+str(timeinit))
time.sleep(10)
print("se finaliza "+ str(datetime.datetime.now()) + "en "+str(datetime.datetime.now()-timeinit))

th1 = threading.Thread(target=hacertrabajo,name="th-1")
th2 = threading.Thread(target=hacertrabajo,name="th-2")

th1.start()
th2.start()
timeinit = datetime.datetime.now()
th1.join(5)
print("se finaliza th1 "+ str(datetime.datetime.now()) + "en "+str(datetime.datetime.now()-timeinit))
th2.join(11)
print("se finaliza th2"+ str(datetime.datetime.now()) + "en "+str(datetime.datetime.now()-timeinit))

Da el resultado siguiente.

PS C:\Users\jordi\Documents\python\multithread> python multi.py
se inicia 2018-02-26 22:22:31.651966
se inicia 2018-02-26 22:22:31.652945
se finaliza th1 2018-02-26 22:22:36.653236en 0:00:05.000291
se finaliza 2018-02-26 22:22:41.653288en 0:00:10.001322
se finaliza 2018-02-26 22:22:41.654265en 0:00:10.001320
se finaliza th22018-02-26 22:22:41.655247en 0:00:10.002302
PS C:\Users\jordi\Documents\python\multithread>

Tal y como indica la documentacion lo normal de join() seria despues hacer algo con el thread como

dissabte, 17 de febrer del 2018



PlyGround with Python 1

how easy is python and sqlite3

import sqlite3
import datetime

def createDataBase():
conn = sqlite3.connect('control.db')
c = conn.cursor()
c.execute('create table control( nombre TEXT, fechaini timestamp, fechafin timestamp)')
c.close()

def pupulateDataBase():
conn = sqlite3.connect('control.db')
c = conn.cursor()
c.execute('insert into control values (?,?,?)',('registro 1',datetime.datetime.now(),datetime.datetime.now()))
conn.commit()
conn.close()

def pupulateDataBaseWhitNull():
conn = sqlite3.connect('control.db')
c = conn.cursor()
c.execute('insert into control values (?,?,?)',('registro 1',datetime.datetime.now(),None))
conn.commit()
conn.close()
def fetchDataBase():
conn = sqlite3.connect('control.db')
c = conn.cursor()
for row in c.execute('SELECT * FROM control'):
print(row)


createDataBase()
pupulateDataBase()
pupulateDataBaseWhitNull()
fetchDataBase()


(test) C:\Users\jordi\jordi\workspaces\python\test>python testsqlite.py
('registro 1', '2018-02-17 10:48:47.235088', '2018-02-17 10:48:47.235088')
('registro 1', '2018-02-17 10:48:47.354523', None)


LightWeight Python Envirotment with Visual Studio 

Create a virtualenv with virtualenv and later activate it running the activate script.

Open the VSC and creaate a fill called .env with the variable PYTHONPATH pointing to the site-packages where the virualenv located all the libraries already download by PIP.

PYTHONPATH=C:\Users\jordi\jordi\workspaces\python\test\Lib\site-packages