How do I convert an integer that is stored in a varchar table to hour and minute?
The data is saved in MySQL in this way example: 1030
and I need to show it as 10:30 am
.
Can a conversion be done in PHP or from MySQL?
How do I convert an integer that is stored in a varchar table to hour and minute?
The data is saved in MySQL in this way example: 1030
and I need to show it as 10:30 am
.
Can a conversion be done in PHP or from MySQL?
I have this example string in Javascript, "246126667"
, and I want to get all the substrings that have any 2 numbers on the left and a 6 at the end, that is, ["246","126","266","666"]
, and for that I apply a match
with the regular expression [0-9]{2}6
, and the parameter g
to get the results, but it doesn't work as I want.
console.log(
"246126667".match(/[0-9]{2}6/g)
)
The problem is that instead of returning all 4 numbers, it only returns ["246","126"]
. Is it possible to solve this using regular expressions? Is there any other way?
I'm new to working with asynchronous tasks and I'm going crazy. When I finish what I have in hand I will be able to study more about this, but now I'm running out of time.
My question is the following: I need to validate a form from the client (I will also do it from the server, but I want double security). What I want to validate is when uploading a file, verify that it is an image . There are many methods out there that parse the extension or return the mime/type but it is wrong as you can try changing the extension to an mp3 and jpg and it will tell you that the mime is jpg.
I started seeing an example that read 4 bits of the file and then depending on those 4 bytes you can know what type of file it is . What happens is that the code that I started to make I don't know how to implement it.
What I want it to do is the following: from the form you select an image, and when you select one, read its initial 4 bytes, compare it and if it really is among those admitted, then show a preview... if not, then an error message is displayed saying invalid file.
What I need is for the checkFileType function to return a value to me $('input[type=file]#imagencabecera').change(function()
and so, after validation, if it is correct, the preview is shown on the screen.
This is the code that remains to be tweaked:
$('input[type=file]#imagencabecera').change(function(){
var file = (this.files[0].name).toString();
var type = (this.files[0].type).toString();
var reader = new FileReader();
console.log(type);
$('#file-info').text('');
$('#file-info').text(file);
reader.onload = function (e){
$('#filepreview img').attr('src', e.target.result);
}
reader.readAsDataURL(this.files[0]);
});
function checkFileType(file){
if (window.FileReader && window.Blob)
// All the File APIs are supported. Si soporta HTML5 FileReader y Blob
{
var slice = file.slice(0,4); // Get the first 4 bytes of a file
var reader = new FileReader(); // Create instance of file reader. It is asynchronous!
reader.readAsArrayBuffer(slice); // Read the chunk file and return to blob
reader.onload = function(e) {
var buffer = reader.result; // The result ArrayBuffer
var view = new DataView(buffer); // Get access to the result bytes
var signature = view.getUint32(0, false).toString(16); // Read 4 bytes, big-endian,return hex string
switch(signature) // Every file has a unique signature, we can collect them and create a data lib
{
case "89504e47": file.verified_type = "image/png"; break;
case "47494638": file.verified_type = "image/gif"; break;
case "FFd8FFe0": file.verified_type = "image/jpeg"; break;
case "FFd8FFe1": file.verified_type = "image/jpeg"; break;
case "FFd8FFe2": file.verified_type = "image/jpeg"; break;
case "FFd8FFe3": file.verified_type = "image/jpeg"; break;
case "FFd8FFe8": file.verified_type = "image/jpeg"; break;
default: file.verified_type = 0;
}
}
}
else
// File and Blob are not supported
{
}
}
Thank you so much for everything.
I have information stored in a popover
and I want it to adapt to the content it has, but I can't find how. Here the example:
$( document ).ready(function() {
$('#prueba').html(funcion());
$('[data-toggle="popover"]').popover({
html : true
});
});
function funcion(){
var json = [{
"id_procesos": 3,
"p": "Llenado de productos",
"unidad_teorica": 33333,
"udm": "ml",
"velocidad": 120
},
{
"id_procesos": 2,
"p": "Mezclaaaaaaaaaaa",
"unidad_teorica": 200,
"udm": "gg",
"velocidad": null
}];
console.debug(json);
var procesos = "<table class='table table-hover'><tr><th>Nombre</th><th>Unidad Teórica</th><th>Velocidad</th><th>Tiempo Teórico</th></tr>";
$( json ).each(function( i, j ) {
procesos += "<tr>";
procesos += "<td>"+j.p + "</td>";
procesos += "<td>"+j.unidad_teorica + " "+j.udm+"</td>";
if(j.velocidad){
procesos += "<td>"+j.velocidad + "<sup>"+ j.udm+" </sup>/<sub>min</sub></td>";
procesos += "<td>"+tiempo_teorico(j.unidad_teorica,j.velocidad,'1') +"</td>";
}else{
procesos += "<td></td>";
procesos += "<td></td>";
}
procesos += "</tr>";
});
procesos += "</table>";
return '<a href="#" data-toggle="popover" title="Procesos" data-content="'+procesos+'">Info</a>';
}
function tiempo_teorico(c_u_t, c_v, c_u_m){
var result = '';
if(c_v==''){
return result;
}else if(c_v==0){
result = 'La Velocidad del Producto no puede ser igual a 0';
return result;
}else if((c_u_t!='') && (c_v!='') && (c_u_m!=null) && (c_u_m!='')){
var time = Math.floor( (c_u_t/c_v)*60 );
var hours = Math.floor( time / 3600 );
var minutes = Math.floor( (time % 3600) / 60 );
var seconds = time % 60;
//Anteponiendo un 0 a los minutos si son menos de 10
minutes = minutes < 10 ? '0' + minutes : minutes;
//Anteponiendo un 0 a los segundos si son menos de 10
seconds = seconds < 10 ? '0' + seconds : seconds;
result = hours + ":" + minutes + ":" + seconds; // 2:41:30
return result;
}
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="prueba"></div>
NOTE: I know
mixeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeIt is not a word that they will insert but you never know if the user will use a long word and to avoid future problems I want him to
popover
adapt to the content.
PS: thanks in advance to anyone who can give me their help and their time :D
how can i convert this
[{"name":"All"},{"name":"NodeJS"},{"name":"ReactJS"},{"name":"PHP"},{"name":"Wordpress"},{"name":"Joomla"}]
In this
["All", "NodeJS", "ReactJS", "PHP", "Wordpress", "Joomla"]
It may be a very simple thing but I have no idea how to do it