I have doubts regarding the mentioned operator, here is an example, what role does it play?
computed: {
...mapGetters({
vuexGetter: "getter",
}),
},
I have doubts regarding the mentioned operator, here is an example, what role does it play?
computed: {
...mapGetters({
vuexGetter: "getter",
}),
},
I need to optimize my code. My boss asked me but I don't know how to do it.
I considered all possible validations, what would they remove or what would they add?
public obtenerNum() {
long numFI = daoF.getNumFI();
long numFA = daoF.getNumFA();
if (numFI>=0 && numFA>=0) {
if (numFI == numFA) {
if (numFI == 0) {
return numFI + 1;
}
return numFI + 1;
} else if (numFI > numFA) {
return numFI + 1;
} else if (numFA > numFI) {
return numFA + 1;
} else {
return -1;
}
} else {
return -1;
}
}
Hello, good morning, I have problems with my switches because when I click on the pager to go to the next page, the switches lose their design. I am filling the table with Ajax and then I place the javascript of the switch plugin.
Do you have any idea why the switch is only applied on the first elements of the table?
I share my code
Table
function getAlumnosRadiusAjax() {
$.ajax({
url : "<?php echo base_url('Radius/getAlumnosRadiusAjax')?>",
type: "POST",
dataType: "JSON",
success: function(data) {
console.log(data);
var html = '';
var btn_switch = '';
var contador = 1;
var filas = data.length;
for (i = 0 ; i < filas; i++){
if (data[i].wifi_status == "enabled") {
btn_switch = "<input type='checkbox' name='switch-wifi-status' onclick='mensajePrueba();' id='switch-wifi-status' checked data-bootstrap-switch>";
} else {
btn_switch = "<input type='checkbox' name='switch-wifi-status' id='switch-wifi-status' checked data-bootstrap-switch>";
}
html += `<tr>
<td>${contador}</td>
<td>${data[i].idPerson}</td>
<td>${data[i].name}</td>
<td>${data[i].instEmail}</td>
<td>${data[i].carrer}</td>
<td>${data[i].type}</td>
<td>
${btn_switch}
</td>
<td>
<div class="btn-group btn-group-sm">
<a href="#" class="btn btn-info" title="Autorizar" onclick="updateAlumnosRadiusAjax('${data[i].enrollment}');"><i class="fas fa-unlock"></i></a>
<a href="#" class="btn btn-info" title="Clave" onclick="message_success('${data[i].value}');"><i class="fas fa-key"></i></a>
<a href="#" class="btn btn-info" title="Generar contraseña"><i class="fas fa-exclamation-triangle"></i></a>
<a href="#" class="btn btn-info" title="Cambiar contraseña email"><i class="fas fa-unlock-alt"></i></a>
<a href="#" class="btn btn-info" title="Enviar mail"><i class="fas fa-paper-plane"></i></a>
</div>
</td>
</tr>`;
contador++;
}
$('#tbody-radius').html(html); //inserto los registros a la tabla
$('#tabla_radius_alumnos').DataTable(); //activo e DataTables
},
error: function (jqXHR, textStatus, errorThrown) {
alert("algo salio mal");
}
});
}
<section class="content">
<div class="container-fluid">
<!-- /.row -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">DataTable with default features</h3>
</div>
<!-- /.card-header -->
<div class="card-body table-responsive p-0">
<table id="tabla_radius_alumnos" class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Nombre</th>
<th>Email</th>
<th>Carrera</th>
<th>Grupo</th>
<th>Estatus</th>
<th>Movimientos</th>
</tr>
</thead>
<tbody id="tbody-radius">
</tbody>
<tfoot>
<tr>
<th>#</th>
<th>ID</th>
<th>Nombre</th>
<th>Email</th>
<th>Carrera</th>
<th>Grupo</th>
<th>Estatus</th>
<th>Movimientos</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
</div>
</div>
<!-- /.row -->
</div><!-- /.container-fluid -->
</section>
New code outside my function
// Ejecutar hasta que se haya cargado el DOM
$(function() {
// Inicializar el plugin sobre elementos específicos
$("input[data-bootstrap-switch]").bootstrapSwitch();
// Delegar evento
$('#tbody-radius').on('switchChange.bootstrapSwitch', 'input[data-bootstrap-switch]', function(event, state) {
// Activar diseño de switch
$("input[data-bootstrap-switch]").each(function(){
$(this).bootstrapSwitch('state', $(this).prop('checked'));
});
});
});
Result (check that it only applies to the elements of tab 1 and not to those of tab 2 of the pager)
Where in my code should I put the plugins switch javascript?
As a result of this question
java.lang.NoClassDefFoundError with explicit CLASSPATH
It has emerged me a doubt. The Oracle documentation onCLASSPATH
tells us:
The class path tells JDK tools and applications where to find third-party and user-defined classes -- that is, classes that are not Java extensions or part of the Java platform. The class path needs to find any classes you've compiled with the javac compiler -- its default is the current directory to conveniently enable those classes to be found ... Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:
- For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
- For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
- For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).
Multiple path entries are separated by semi-colons.
However, from my experience, I have come to the conclusion that all the tutorials on the internet and the documentation itself are wrong .
Let's put a minimal code file, which uses some external library:
import com.google.gson.Gson;
public class MCVE {
public static void main( String [] args ) {
System.out.println( " ***** Iniciando la prueba *****" );
MCVE mcve = new MCVE( );
String json = new Gson( ).toJson( mcve );
System.out.println( json );
System.out.println( " ***** Prueba terminada *****" );
}
}
Likewise, a pom.xml
minimum, but that we copy the dependencies to a directory (in this case, target/libs
):
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>es.stackoverflow.com</groupId>
<artifactId>MCVE</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>MCVE</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
All this placed in a more or less standard directory hierarchy:
/mcve
+-pom.xml
+-src
+-main
+-java
+-MCVE.java
We compile it:
>mvn package
After which, our directory hierarchy contains:
/mcve
+-pom.xml
+-src/
| +-main/
| +-java/
| +-MCVE.java
+-target/
+-MCVE-1.0.jar
+-libs/
+-gson-2.8.5.jar
Also, we look inside the .jar
, the file MANIFEST.MF
:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: root
Created-By: Apache Maven 3.6.3
Build-Jdk: 1.8.0_252-ea
Main-Class: MCVE
Now, we run it:
>cd target
>CLASSPATH='libs/' java -jar MCVE-1.0.jar
But it seems that he doesn't like it :
>java -jar MCVE-1.0.jar
***** Starting test *****
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/Gson
at MCVE.main(MCVE.java: 9)
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun .misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 1 more
We continue testing all possible ways to indicate the CLASSPATH
:
>CLASSPATH='libs' java -jar MCVE-1.0.jar
>CLASSPATH='/root/mcve/target/libs/' java -jar MCVE-1.0.jar
>CLASSPATH='/root/mcve/target/libs' java -jar MCVE-1.0.jar
>export CLASSPATH='/root/mcve/target/libs/'; java -jar MCVE-1.0.jar
>CLASSPATH='libs/gson-2.8.5.jar' java -jar MCVE-1.0.jar
>CLASSPATH='/root/mcve/target/libs/gson-2.8.5.jar' java -jar MCVE-1.0.jar
...
>java -cp 'libs/' -jar MCVE-1.0.jar
>java -cp 'libs/' -jar MCVE-1.0.jar
>java -cp '/root/mcve/target/libs/gson-2.8.5.jar' -jar MCVE-1.0.jar
...
In all cases I get the same exception.
I have a flat file in UNIX format delimited by ; (Semicolon) with the following structure:
2020-01-30;1010;1
2020-01-30;1150;2
2020-02-03;1190;3
I must replace each character from position (12,4)
0->1
1->2
2->3
3->4 etc etc...
Staying:
2020-01-30;2121;1
2020-01-30;2261;2
2020-02-03;2201;3
I have tried several strategies with no success:
sed -i 's/0/9/g; s/1/8/g; s/2/7/g; s/3/6/g; s/4/5/g; s/5/4/g; s/6/3/g; s/7/2/g; s/8/1/g; s/9/0/g' data.dat > data1.dat
Do you have any strategy?