Saturday, September 16, 2017

Connect to Cassandra in Python

pip install cassandra-driver


from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider


query ="""select * from xyx.xyx"""

auth = PlainTextAuthProvider (username='username', password='password')
clusterhosts=['10.224.201.31']
cluster = Cluster(clusterhosts, auth_provider=auth,port=9042,control_connection_timeout=100)
s = cluster.connect('storeprices')
r= s.execute(query)
for x in r:
    print x.effective_dt , x.store_nbr




control_connection_timeout=100 without this i was getting timeout . Also, there is another property which controls read connection timeout.

Saturday, September 9, 2017

How to use Google Cloud Storage Service

Using google cloud storage service

Use this link to get your key .
Use SERVER TO SERVER option for downloading key.
Download the json key to a file .

GET Google Cloud Storage Key here


THIS IS YOUR BUCKET is the name in
https://console.firebase.google.com/project/YOUR PROJECT NAME/storage/YOUR BUCKET NAME/files

Sample Program Below

package com.example.cloudstorage.demo;

import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.Tuple;
import com.google.cloud.WriteChannel;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;


public class GoogleCloudSave {
    private static String xxx = "" +
            "{\n" +
            "  \"type\": \"service_account\",\n" +
            "  \"project_id\": \"PROJECT\",\n" +
            "  \"private_key_id\": \"PRIVATE KEY ID\",\n" +
            "  \"private_key\": "\"YOUR KEY DATA HERE " +
            "  \"client_email\": \"your data here\",\n" +
            "  \"client_id\": \"113028132990675148678\",\n" +
            "  \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n" +
            "  \"token_uri\": \"https://accounts.google.com/o/oauth2/token\",\n" +
            "  \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n" +
            "  \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/896954817105-compute%40developer.gserviceaccount.com\"\n" +
            "}\n";
   private static  Storage storage;
    public static void main(String[] args) {
        try {
            InputStream is = new ByteArrayInputStream(xxx.getBytes());
          storage  = StorageOptions.newBuilder()
                    .setCredentials(ServiceAccountCredentials.fromStream(is))
                    .build()
                    .getService();


            UploadAction uaction = new UploadAction();
            Tuple parse = uaction.parse("/tmp/hello.txt", "THIS IS YOUR BUCKET");
            try {
                uaction.run(storage,parse);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private abstract static class StorageAction<T> {

        abstract void run(Storage storage, T arg) throws Exception;

        abstract T parse(String... args) throws Exception;

        protected String params() {
            return "";
        }
    }


    
    private static class UploadAction extends StorageAction> {
        @Override        public void run(Storage storage, Tuple tuple) throws Exception {
            run(storage, tuple.x(), tuple.y());
        }

        private void run(Storage storage, Path uploadFrom, BlobInfo blobInfo) throws IOException {
            if (Files.size(uploadFrom) > 1_000_000) {
                // When content is not available or large (1MB or more) it is recommended                // to write it in chunks via the blob's channel writer.                try (WriteChannel writer = storage.writer(blobInfo)) {
                    byte[] buffer = new byte[1024];
                    try (InputStream input = Files.newInputStream(uploadFrom)) {
                        int limit;
                        while ((limit = input.read(buffer)) >= 0) {
                            try {
                                writer.write(ByteBuffer.wrap(buffer, 0, limit));
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            }
                        }
                    }
                }
            } else {
                byte[] bytes = Files.readAllBytes(uploadFrom);
                // create the blob in one request.                storage.create(blobInfo, bytes);
            }
            System.out.println("Blob was created");
        }

        @Override        Tuple parse(String... args) throws IOException {

            Path path = Paths.get(args[0]);
            String contentType = Files.probeContentType(path);
            String blob = args.length < 3 ? path.getFileName().toString() : args[2];
            return Tuple.of(path, BlobInfo.newBuilder(args[1], blob).setContentType(contentType).build());
        }

        @Override        public String params() {
            return "  []";
        }
    }


}









Thursday, August 10, 2017

Add colors to terminal and vi in MACos

http://tiriboy.blogspot.in/2015/01/syntax-highlighting-bash-terminal-and.html

Monday, June 26, 2017

MAPAPP



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

Option -O (upper-case O) is important. Without this, curl will start dumping the downloaded file on the stdout. Using -O, it downloads the files in the same name as the remote server. In the above example, we are downloading strx25-0.9.2.1.tar.bz2, so the downloaded file will also be the same name.

yum update
yum search any-package

yum info any-package

yum install any-package
yum list something

yum list recent

yum list installed
yum list available

yum list all

lsof -i :port
lsof -i :80
https://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/#
https://www.cyberciti.biz/faq/yum-install-wget-redhat-cetos-rhel-7/
https://tecadmin.net/install-apache-maven-on-centos/
CREATE KEYSPACE “KeySpace Name”
WITH replication = {'class': ‘Strategy name’, 'replication_factor' : ‘No.Of  replicas’}


https://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/#

Sunday, May 28, 2017

Songs

http://www.mensxp.com/culture/music/34152-20-songs-that-will-give-you-all-the-feels-like-no-other-song.html?utm_source=FB&utm_medium=Paid