Skip to content

Instantly share code, notes, and snippets.

View cploutarchou's full-sized avatar

Christos Ploutarchou cploutarchou

View GitHub Profile
@cploutarchou
cploutarchou / jsonToXml.go
Last active April 13, 2023 07:15
This application is a JSON-to-XML converter that reads JSON objects from a file, converts them into XML format, and saves the resulting XML to a new file. It handles JSON objects separated by commas, sanitizes keys and values by replacing special characters with underscores, and validates the resulting XML file to ensure it is well-formed.
package main
import (
"bufio"
"encoding/json"
"encoding/xml"
"fmt"
"io"
"os"
"strings"
@cploutarchou
cploutarchou / renderButtons.js
Created April 10, 2020 16:50
Render Buttons on UI
const renderPaginationButtons = (page, resultNumber, resultsPerPage) => {
const pages = Math.ceil(resultNumber / resultsPerPage);
let button;
switch (true) {
case page === 1 && pages > 1:
// Show only button go to next page
button = createPaginationButtons(page, "next");
break;
case page < pages:
// Show both buttons previous / next
@cploutarchou
cploutarchou / customForEachFunction.js
Created March 23, 2020 15:18
Create Custom For Each Function for Node List
forEach = function (percentages) {
//1st we select fields we want add new values
var fields = document.querySelectorAll(DOMStrings.expensesPercentageLabel);
//The we pass a function on var eg nodeListForeach
// we pass the fields list and we retrunt a callback function on secont parameter
// we loop inside of fields and we pass on callback function the field index no and second
// the current field value.
var nodeListForeach = function (fields, callback) {
for (var i = 0; i < fields.length; i++) {
@cploutarchou
cploutarchou / stringToHTML.js
Last active March 16, 2020 17:05
Convert a template string into HTML DOM nodes
/**
* Convert a template string into HTML DOM nodes
* @param {String} str The template string
* @return {Node} The template HTML
*/
stringToHTML (str) {
let dom = document.createElement('div');
dom.innerHTML = str;
return dom;
};
@cploutarchou
cploutarchou / nodeListToArray.js
Created March 12, 2020 22:20
Convert dom nodelist to array
//Select Needed Dom Elements
const boxes = document.querySelectorAll('.box');
// ES5
var boxesArr5 =Array.prototype.slice.call(boxes);
// ES6
const boxesArray6 = Array.from(boxes);
@cploutarchou
cploutarchou / assignArrayPropertiesToObject.php
Created March 12, 2020 22:18
assign array properties and values to class object
function assignArrayPropertiesToObject($array)
{
$class = new self::$get_class;
if (!empty($array)) {
foreach ($array as $prop => $value) {
$class->$prop = $value;
}
}
return $class;
@cploutarchou
cploutarchou / Send data using the POST method.js
Created March 12, 2020 22:16
Send data using the POST method"
//Similar to`jQuery.get()`,`jQuery.post()`loads data from the server using a HTTP POST request. The code below demonstrates how to send a POST request to`page.php`when`button`is clicked.
jQuery("button").click(function(){
jQuery.post("page.php", function(data, status){
alert("Data: " + data + "\\\\nStatus: " + status);
});
});
@cploutarchou
cploutarchou / Select Random item from Array.js
Created March 12, 2020 22:13
Select Random item from Array
function selectRandomArrayItem(array) {
return array[Math.floor(Math.random() * array.length)];
}
@cploutarchou
cploutarchou / format Money.js
Last active March 12, 2020 22:13
a javascript function to format money.js
formatMoney = (amount, decimalCount = 2, decimal = ",", thousands = ".") => {
try {
decimalCount = Math.abs(decimalCount);
decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
const negativeSign = amount < 0 ? "-" : "";
let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString();
let j = (i.length > 3) ? i.length % 3 : 0;
@cploutarchou
cploutarchou / Get all values from form and send it to a page.js
Created February 5, 2020 15:37
Get all values from form and send it to a page Javascript,Jquery,Ajax
jQuery( document ).ready(function() {
jQuery( "#submit" ).click(function() {
jQuery.post( "https://yoursite.com/yourpage.php", jQuery('#form').serialize())
.done(function( data ) {
alert(data);
});
return false;
});
});