Skip to content

Instantly share code, notes, and snippets.

View fjtorres's full-sized avatar

Francisco Javier Torres fjtorres

  • Sanlúcar de barrameda (España)
View GitHub Profile
@fjtorres
fjtorres / customize_freshdesk_widget.js
Created September 27, 2022 08:22
These javascript functions will help you to customize Freshdesk widget when you are using the free tier. Basically these functions will add custom styles to launcher icon and override some stiles for the widget.
async function redesignFreshdeskWidgetLauncher() {
const frame = await waitFor('#launcher-frame', document);
const frameHead = frame.contentDocument.getElementsByTagName("head")[0];
const new_style_element = document.createElement("style");
new_style_element.textContent = ".launcher-button, .launcher-button:hover, .launcher-button:active { background: none; background-color: #8CC448 !important; transition: none !important;animation: none !important;}"
frameHead.appendChild(new_style_element);
@fjtorres
fjtorres / NodemailerServiceImpl.java
Created April 13, 2022 07:47
Utility class to use Nodemailer API to create Ethereal.email accounts from Java
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.mail.Flags;
import jakarta.mail.Folder;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.HttpURLConnection;
@fjtorres
fjtorres / WebServerTest.java
Last active March 31, 2022 18:04
Simple HTTP server with Java
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@fjtorres
fjtorres / Systemd service definition
Last active January 14, 2023 10:44
File to define a service to launch a Java application using Systemd in Linux.
[Unit]
Description=Start Java Application
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=on-failure
RestartSec=1
User=root
@fjtorres
fjtorres / logback.xml
Created February 19, 2019 08:55
Logback configuration to use Logentries/InsightOps with json layout provided by Logstash.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<customFields>{"application":"app-name"}</customFields>
</encoder>
</appender>
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfDictionary;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfNumber;
import com.itextpdf.text.pdf.PdfReader;
@fjtorres
fjtorres / HttpConnectorConfiguration.java
Last active December 14, 2017 09:09
Enable HTTP listener with undertow when you have enabled HTTPS in Spring boot.
import io.undertow.Undertow;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.undertow.UndertowBuilderCustomizer;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Configuration class to enable HTTP listener (when HTTPS is enabled in Spring Boot we need to add support to HTTP manually).
@fjtorres
fjtorres / MoveToParentDirTest.java
Created November 27, 2017 11:46
Moves all files from child directories to root folder and delete empty directories.
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.atomic.AtomicInteger;
DECLARE
flag NUMBER;
BEGIN
flag:=127;
while flag < 13892 loop
@fjtorres
fjtorres / pagination_ajax.js
Last active April 17, 2017 14:58
Pagination to ajax with JQuery
$("#identifier").on("click", ".pagination a", function(e) {
e.preventDefault();
var $url = $(this).attr("href");
$.ajax({
url: $url,
success: function(result){
$("#identifierContainer").replaceWith($(result).find("#identifierContainer"));