domingo, 24 de janeiro de 2016

blogspot : how to make code syntax hilight in a blog

Hi,
this shows a simple way to make code syntax highlighter on blogger.com.

on blog administration, goto :

1. template
2. edit html button
3. before the head put :










Than when you need to put a source example make:


all code here

python, download all files from a site

Hi ,
will not be cool to download all file type from a site, just to not delay to much time to do it.

There are some challenges to do it with Python:

1. how to accept cookies (cookiejar)
2. how to decode a site into elements (BeautifulSoup)


Here is the code:


"""
downloadAllPdfs.py
    Downloads all the pdf on the supplied URL, and saves them to the
    specified output file ("/test/" by default)

Usage:
    python downloadAllPdfs.py http://example.com/ [output]
"""

from bs4 import BeautifulSoup 
import urllib.request as urllib2
import http.cookiejar
import sys

def _downloadFileFromServer(finalFileUri,outputpath):
    print("==> _downloadFileFromServer %s" % finalFileUri )
    filename=finalFileUri.rsplit('/', 1)

    cj = http.cookiejar.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    page = opener.open(finalFileUri)
    data = page.read()
    page.close()
    opener.close()

    print("==> _downloadFileFromServer %s" % outputpath+filename[1] )

    FILE = open(outputpath+filename[1], "wb")
    FILE.write(data)
    FILE.close()

def _downloadFolder(url,outputpath):
    print("\tdownload %s" % url )
    cj = http.cookiejar.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    
    page = opener.open(url)
    soup = BeautifulSoup(page)
    #print (soup.prettify(None,"minimal"))
    
    for lnk in soup.findAll("a"):
        print ("\t\tcheck lnk %s" % lnk)
        
        
        if lnk.has_attr('href'):
            filename = lnk["href"]
        else:
            continue
        
        
        if filename is None:
            continue


        if filename.find(".pdf") >=0 or filename.find(".zip") >=0  :
            finalFile=filename
            if filename.find("http://")<0 :
                finalFile=url + filename
            _downloadFileFromServer(finalFile,outputpath)
            
    print("DONE download %s" % url )
    print("" )
            

def main():
    print ("==init==")
    url=sys.argv[1]
    outputpath=sys.argv[2]+"\\"
    print ("download from %s"%url)
    print ("to %s"%outputpath)

    _downloadFolder(url,outputpath)
    print ("==done==")


if __name__ == "__main__":
    main()



Raspberry 2 - part 3- blink leds with Python

Hi,
this tutorial today, will show how to use the raspberry and the linux installed, to control the GPIO with a simple Python script.

So the ideia, is to use the GPIO 17 and 18, to swith on and off, 2x LED´s.
Each LEd is connected to a GPIO with a serial resistance (1k) to limit the output current.
After a resistance is the LED.

Before connect the GPI check the pin on the raspberry site.
The GPIO of my raspberry is:


The schematic for the connections shall be:


The code of script is:

'''
Created on 23/01/2016

@author: tecbea
'''
# import gpio
import RPi.GPIO as GPIO
# import time 
import time


def _ledLoop (io,num,sleep):
    for num in range(1,num):
        print "io %d on" % io
        GPIO.output(io,GPIO.HIGH)
        time.sleep(sleep)
        print "io %d off" % io
        GPIO.output(io,GPIO.LOW)
        time.sleep(sleep)

def main():
    print ("==init==")

    # set mode on gpio 18
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    # output mode
    GPIO.setup(17,GPIO.OUT)
    GPIO.setup(18,GPIO.OUT)
    
    _ledLoop(17,10,0.5);
    _ledLoop(18,10,0.5);
    _ledLoop(17,20,0.1);   
    _ledLoop(18,20,0.1);   

# ###############################
if __name__ == "__main__":
    main()


best

sexta-feira, 22 de janeiro de 2016

Wildfly, Eclipse Luna, Hot deploy

Hi,

Is there a way yo have a maven projet in eclipse, and make auto deploy of objects changes and html changes ?

Yes Eclipse can do it, i still did not put to work when a class has a new method or attribute.

1. with eclipse luna
2. with wildfly 8
3. a maven project
4. make "run as " , run on server, choose wildfly 8
5. on servers -> start  the server and deploy the project
6. on servers, dbl click on the server, it will appear the server configuration

On "Application reload behaviour"
click on intercept hot code and put on the edit box "\.jar$|\.class$"

On "publishing"
choose automatic publish after a build event

7. If you want to pass parameters to Wildfly startup, click on open launch configuration , example

 -Dproperties.file=/hmi.properties

best

terça-feira, 5 de janeiro de 2016

Redis performance with JEDIS - II


7. And continue the benchs for publish - subscribe :

 I was not able to do the best in term of tunning.
Seems that when subscribers are slow i usually have "conn fail" and events are dropped. Remember this is mem database .


pubNumber SubsTotal OpsTime msOp/sec
155000002955169204.7377
1510000004570218818.3807





1105000004408113430.127
11010000007478133725.5951





120500000747966853.85747
12010000001271178672.01636


8.



segunda-feira, 4 de janeiro de 2016

Install Linux on Raspberry PI2 - part 2 - setup static ip address


Hi,

as described on Part 1, after flashing the sd card with the Raspberrian Jessie, the pi is ready to start with configurations.

After a boot, the first thing, is what is the ipaddress of the eth0; well it comes with default dhcp configuration.

After some inspection, i found that the /etc/networks/interfaces is not working as older linux.

To configure with a static ip address make this:

1. goto /etc/network/interfaces, and configure ip interface mode for eth0

iface eth0 inet manual

2. the static ip configuration is done on /etc/dhcpcd.conf

add to the end of the file

interface eth0
static ip_address=192.168.0.1/24
static routers=192.168.0.254

With this configuration the pi will be with ipv4 192.168.0.1
Configure your PC with ipv4 : 192.168.0.2, with netmask 255.255.255.0

Than test the conection :

ping 192.168.0.1

And static ip is done.
After this download a ssh like putty or excelent mobaxterm.

The login credentials will be :

mode : ssh2
user :  pi
password : raspberry


That´s it.

best

domingo, 3 de janeiro de 2016

Install Linux on Raspberry PI2 - part 1

Hi,
just received a Raspberry pi2 , from a web foreign supplier.

It does not boot, the red and green led are on.
With some investigation, it seems that maybe the uSDCard do not have a linux boot image.

On https://www.raspberrypi.org/downloads/, we have several options:
NOOBS, Raspbian (that i will use to start, since is based on debian).

3x steps to follow:

1. download the image
2. get a SD card adapter to put the uSDCard on the PC
3. get a image writer( win32diskimage or SDFormatter )
or win32diskimager
or  sdcard

than unzip the image, choose the img and write to the sd card.
Than put the sdcard on the raspberry and boot.

best


Java Obfuscate Properties

Hi there how many times we have fuckin stupid commentaries of , hey the code has a password... bullshit you can always get the password... ...