martes, 8 de enero de 2019

GPG

Create a key pair.

gpg --gen-key

 List keys.

 gpg --list-keys

Export a public key

 gpg --export UID file.pub

Import a public key 

gpg --import file.pub

Create an encrypted and signed file. 

gpg -se -u "Sender User Name" -r "Receiver User Name" somefile

Decrypt a file. 

gpg -d mydata.tar.gpg

Typical key management with OpenSSL

Generate private key:
openssl genrsa -aes128 -passout pass:foobar -out privkey.pem 2048
Extract public key from private key:
openssl rsa -pubout -in privkey.pem -out pubkey.pem
Display data from the key file:
openssl rsa -text -in private_key.pem
Remove the key proteccion.
openssl rsa -in [file1.key] -out [file2.key]

LVM How to

create the partitions:

fdisk /dev/sdb

Partition type:
8e

pvcreate /dev/sdb1
pvcreate /dev/sdb2

vgcreate vgtest /dev/sdb1 /dev/sdb2
vgscan

lvcreate -L 1G vgedir


pvcreate /dev/sdb3
vgextend vgtest /dev/sdb3
vgscan

lvextends -L 500M vgedir

linux-f0cx:/ # resize2fs /dev/vgedir/tlv +500M
resize2fs 1.41.9 (22-Aug-2009)
Please run 'e2fsck -f /dev/vgedir/tlv' first.

linux-f0cx:/ # e2fsck -f /dev/vgedir/tlv
e2fsck 1.41.9 (22-Aug-2009)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgedir/tlv: 34/65536 files (0.0% non-contiguous), 12667/262144 blocks

linux-f0cx:/ # resize2fs /dev/vgedir/tlv +1500M
resize2fs 1.41.9 (22-Aug-2009)
Resizing the filesystem on /dev/vgedir/tlv to 128000 (4k) blocks.
The filesystem on /dev/vgedir/tlv is now 128000 blocks long.



  230  pvcreate /dev/sdb1
  231  pvcreate /dev/sdb2
  232  pvcreate /dev/sdb3
  233  pvcreate /dev/sdb
  234  pvcreate /dev/sdb4
  235  vgcreate vg0 /dev/sdb1 /dev/sdb2
  236  vgdisplay
  237  lvcreate 
  238  lvcreate --help
  239  lvcreate -L 1G var
  240  lvcreate -L 1G /dev/vg0/var
  241  lvcreate -L 1G vg0 var
  242  lvcreate -L 1G vg0 -n var
  243  lvdisplay
  244  mkfs.ext3 /dev/vg0/var
  245  e2fsck /dev/vg0/var 
  246  history

jueves, 1 de marzo de 2018

Spark full transformation cycle.

spark.read.format("csv").option("header","true").load("in/file.csv"); def p(row: Row) = Row(row.getString(0).toUpperCase,row.getString(1),row.getString(2)); rddData.map(p).foreach(println); var transform = inFile.map(row=>(row.getString(0),row.getString(1),row.getString(2),"XXXXXXXXXXXXXXXX")). transform.write.format("csv").option("header","false").save("out/names.csv");

Jenkins: trigger a job via remote request

We can use curl to trigger the job execution (with curl and some hooks or with incron) https://ci.tcpip.tech/view/Experimentos/job/CI-Template/build?token=Al-fa1fa_316 https://ci.tcpip.tech/view/Experimentos/job/CI-Template/buildWithParameters?token=Al-fa1fa_316

lunes, 19 de febrero de 2018

Notepad for Spark (I): Adding to your entries an UUID

Create a DataFrame:

var in=spark.read.json("sample.json");

Register the UDF (User Defined Function)

import java.util.UUID
val generateUUID = udf(() => UUID.randomUUID().toString)

Generate a new Column

val withUUID= in.withColumn("uuid",generateUUID());

miércoles, 27 de diciembre de 2017

Guice small code receipt and Spark framework

La clase que utiliza el injector
System.setProperty("user","santi");

Injector injector = Guice.createInjector(new GuiceMod());
ConfigurationService config = injector.getInstance(Key.get(ConfigurationService.class, Names.named("config")));
System.out.println(config.getKey("user"));


threadPool(250,15,30000);


Random random= new Random();
long rand = random.nextLong();

System.out.println("Shutdown code: "+rand);
get("/sample",(req,res)-> {
            return "Hello World!!!";
        });

        get("/sd_"+rand,(request, response) -> {
            stop();
            return "";
        });
El modulo

/**
 * Created by santiago on 12/26/17.
 */
public class GuiceMod extends AbstractModule{


    @Override
    protected void configure() {

    }

    @Provides
    @Singleton
    @Named("config")
    public ConfigurationService getConfig(){
        return new ConfigurationImpl();
    }

}


martes, 17 de octubre de 2017

Deploy to Nexus

With the following snippet you can deploy anything to Nexus. mvn deploy:deploy-file -DgroupId=com.somecompany -DartifactId=project -Dversion=1.0.0 -DgeneratePom=false -Dpackaging=jar -DrepositoryId=nexus -Durl=http://localhost:8081/nexus/content/repositories/releases -DpomFile=pom.xml -Dfile=target/project-1.0.0.jar

Ant as a script director

Hi, this entry on the blog is for using Ant as a scripting integration together with Groovy.

<‍project‍>
<‍property name="groovy.home" value="/home/vagrant/.sdkman/candidates/groovy/current/"/‍>
   <‍property name="groovy.version" value="X.Y.Z"/‍>
   <‍path id="groovy.classpath"‍>
     <‍fileset dir="${groovy.home}/lib"‍>
       <‍include name="**/*.jar"/‍>
     <‍/fileset‍>
   <‍/path‍>
<‍target name="targetSample"‍>
    <‍taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="groovy.classpath"/‍>
      
        ant.ant(antfile:'build.xml'){ // you antfile name
           target(name:'targetTest') // your targetName
           property(name:'param1',value:'theParamValue') // your params name and values
        }
        def salutation="Hello World"
        print(salutation)
       <‍/groovy‍>
 <‍/target‍>
<‍target name="targetTest"‍>
        <‍echo‍>Hola mundo Groovy! <‍/echo‍>
<‍/target‍>
<‍/project‍>
Output
Buildfile: /home/vagrant/ant-tests/build.xml

targetSample:

targetTest:
     [echo] Hola mundo Groovy!
Hello World

BUILD SUCCESSFUL
Total time: 1 second

viernes, 8 de septiembre de 2017

Google Analytics from the command line

Use the following command
curl -d "v=1&tid=UA-104039318-1&cid=111&t=pageView&dp=/b/route&ds=web&cd3=GDL-MEX" 
-X POST www.google-analytics.com/collect

How to perform Single sign-on with Nginx

Insert within server section:
 location = /auth {
            internal;
            proxy_pass              http://localhost:8080/auth.jsp;
            proxy_pass_request_body off;
            proxy_set_header        Content-Length "";
            proxy_set_header        X-Original-URI $request_uri;
        }

        location /examples/ {
            auth_request     /auth;
            auth_request_set $userid $upstream_http_userid;
            auth_request_set $role $upstream_http_role;
            proxy_set_header X-UserId $userid;
            proxy_set_header X-Role $role;
            proxy_pass              http://localhost:8080/examples/;
        }

martes, 15 de agosto de 2017

Converting Java to native code with GCJ

I recently discovered the power of gcc in order to create native executables from Java source code. You never know when are you going to need it, but just in case, is good to know that is there:
gcj -c -g -O MyJavaProg.java
gcj --main=MyJavaProg -o MyJavaProg MyJavaProg.o