Skip to content

Instantly share code, notes, and snippets.

View jsianes's full-sized avatar

Javier Sianes jsianes

  • AWS
  • O Grove, Galicia
  • 07:23 (UTC +02:00)
  • LinkedIn in/jsianes
View GitHub Profile
@jsianes
jsianes / backup-BBDD.sh
Last active January 24, 2022 09:56
This shell-script creates a local MySQL backup file, maintaining a 10 days rotation period (by default. Can be configured on parameters). Controls if there is enough space before doing it and overlap executions.
#!/bin/bash
#
# This script make a local MySQL DB backup
# Developed for RHEL5 by Javier Sianes - jsianes@gmail.com
#
# Start of Parameters
##############################################
USUARIO="username"
PASSWORD="password"
@jsianes
jsianes / ipassign
Last active September 5, 2021 08:04
Script to assign Public IP from Elastic IP pool for instances hosted in AWS. 'ec2-utils' and AWS CLI packages required. Instance role or access keys need to allow at least next EC2 actions: describe-addresses, associate-address and disassociate-address. Shell script is designed to be integrated with instance start-up
#!/bin/bash
# chkconfig: 2345 99 10
# description: Set Public IP from ElasticIP pool during instance startup
# processname: ipassign
# Provides: ipassign
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Set Public IP from ElasticIP pool during instance startup
@jsianes
jsianes / Lottery.java
Created August 18, 2012 10:14
Spotify 'lottery' test program solved
import java.util.Scanner;
import java.io.BufferedInputStream;
public class Lottery {
public static double LotteryProbability (String lottery) {
int m=0,n=0,t=0,p=0,requiredForWin=0;
double result=0.0;
String[] number = lottery.split(" ");
@jsianes
jsianes / mergeExcel.java
Last active April 4, 2016 19:39
A Java application using Apache POI library for merging Excel files
import java.io.*;
import java.util.Map;
import java.util.Vector;
import java.util.HashMap;
import java.util.StringTokenizer;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
@jsianes
jsianes / ReversedBinaryNumbers.java
Last active December 22, 2015 03:29
Spotify 'Reversed Binary' test program solved (https://www.spotify.com/us/jobs/tech/reversed-binary/)
import java.util.Scanner;
public class ReversedBinaryNumbers {
public static void main(String[] args) {
if (args.length == 1) {
Scanner scanner=new Scanner(args[0]);
if (scanner.hasNextLong()) {
long l=scanner.nextLong();
if ((l>0)&&(l<1000000001)) {System.out.println(Long.parseLong(new StringBuilder(Long.toBinaryString(l)).reverse().toString(),2));}
}
@jsianes
jsianes / LCAP.java
Last active December 19, 2015 17:49
This Java code helps you to analyze economic proposals of a contest according to art.85 hiring law of Public Administrations in Spain (Real Decreto 1098/2001,Reglamento LCAP - artículo 85: http://is.gd/uANADN )
import java.io.*;
import java.util.*;
import java.text.*;
public class LCAP {
public static void Ley() {
System.out.printf("Evaluacion segun la LCAP:\n\n"+
"Articulo 85. Criterios para apreciar las ofertas desproporcionadas o temerarias en las\n"+
"subastas.- Se consideraran, en principio, desproporcionadas o temerarias las ofertas que\n"+
@jsianes
jsianes / CSTranslator.sh
Last active December 19, 2015 01:19
A bash shell-script that takes several CSV as input and generates an unified and restructured CSV output
#!/bin/bash
#
# Developed by: Javier Sianes - jsianes@gmail.com
#
# Exit codes:
# 0: Correct program execution
# 1: Total hours doesn't match with partial aggregate hours
# 2: General error or program execution interrupted
# 3: Can't match resource as intern or extern
# 4: Error in command line execution
@jsianes
jsianes / XmltoJson.java
Last active December 19, 2015 01:18
A short Java program that takes any XML file from input and generates a JSON compliant document
import java.io.*;
import java.util.*;
import org.json.*;
/*
JSON library provided by json.org (http://www.json.org/)
*/
public class XmltoJson {
public static void main(String[] args) {
@jsianes
jsianes / wordcount_exec
Last active December 17, 2015 16:29
Execution result for WordCount Hadoop example
[ambari-qa@master-node ~]$ hadoop dfs -ls ./entrada
Found 2 items
drwx------ - ambari-qa hdfs 0 2013-05-23 18:41 /user/ambari-qa/entrada/entrada
-rw------- 3 ambari-qa hdfs 568233984 2013-05-23 20:31 /user/ambari-qa/entrada/input1.txt
[ambari-qa@master-node ~]$ hadoop jar /usr/lib/hadoop/hadoop-examples.jar wordcount ./entrada/input1.txt ./salida
13/05/23 20:38:15 INFO input.FileInputFormat: Total input paths to process : 1
13/05/23 20:38:15 INFO lzo.GPLNativeCodeLoader: Loaded native gpl library
13/05/23 20:38:15 INFO lzo.LzoCodec: Successfully loaded & initialized native-lzo library [hadoop-lzo rev cf4e7cbf8ed0f0622504d008101c2729dc0c9ff3]
13/05/23 20:38:15 WARN snappy.LoadSnappy: Snappy native library is available
13/05/23 20:38:15 INFO util.NativeCodeLoader: Loaded the native-hadoop library
@jsianes
jsianes / WordCount.java
Created May 23, 2013 20:30
WordCount example from Hadoop
package org.myorg;
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;