Code Snippet

Just another Code Snippet site

Random Post :




Java : Parse XML with XPath

InputSource inputSource1 = new InputSource(...);
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
String result = xpath.evaluate("//*[local-name()='AAA']/text()", source, XPathConstants.STRING);

[Java] Hash a string/password (with or without salt)

Method :

    private static final String HASH_METHOD = "SHA-256";

    private String hash(final String password) throws CryptEUException {
        try {
            MessageDigest md = MessageDigest.getInstance(HASH_METHOD);
            md.update(password.getBytes());
            byte byteData[] = md.digest();

            // convert the byte to hex format
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }

            return sb.toString();

        } catch (NoSuchAlgorithmException e) {
            LOGGER.debug("NoSuchAlgorithmException", e);
        }
    }

Call for password only :

hash(password)

Call for password + salt :

hash(password + salt)

Call for password + random salt :

hash(password + RandomStringUtils.randomAlphanumeric(10))

,

[Cassandra] Install Cassandra (Linux)

http://www.liquidweb.com/kb/how-to-install-cassandra-on-centos-6/

yum install jna

vi /etc/yum.repos.d/datastax.repo

[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

yum install dsc20

service cassandra start

service cassandra status

nodetool status

service cassandra stop

cqlsh

Configure Cassandra access :
Edit cassandra.yaml (/etc/cassandra/conf)

Update as follow :

#authenticator: AllowAllAuthenticator
authenticator: PasswordAuthenticator

#authorizer: AllowAllAuthorizer
authorizer: CassandraAuthorizer

Restart service

Connect using default user :
cqlsh -u cassandra -p cassandra localhost 9160

Create new superuser :
CREATE USER dba WITH PASSWORD ‘bacon’ SUPERUSER;

[Arduino] Serial, UART, Raspberry and co

http://blog.oscarliang.net/raspberry-pi-and-arduino-connected-serial-gpio/

http://electroniqueamateur.blogspot.fr/2014/10/communication-rf-433-mhz-entre.html

http://electroniqueamateur.blogspot.fr/2014/05/communication-par-usb-entre-raspberry.html

http://blog.oscarliang.net/connect-raspberry-pi-and-arduino-usb-cable/

http://elinux.org/RPi_Serial_Connection

http://angryelectron.com/rxtx-on-raspbian/

http://pi4j.com/example/serial.html

http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-3

http://www.raspberry-projects.com/pi/programming-in-c/uart-serial-port/using-the-uart
——————-
http://easydomoticz.com/domoticz-raspberry-et-arduino-sont-dans-un-bateau-mysensors-org-partie-1/
Partie 2
Partie 3

Previous Posts Next posts