Skip to content

Instantly share code, notes, and snippets.

View lucaguada's full-sized avatar
:electron:
quanting

Luca Guadagnini lucaguada

:electron:
quanting
  • Trydent
  • Italy
View GitHub Profile
@saumilsdk
saumilsdk / SslUtil.java
Last active October 26, 2023 09:53 — forked from rohanag12/SslUtil.java
Create an SslSocketFactory using PEM encrypted certificate files
/**
* Utility class to read encrypted PEM files and generate a SSL Socket Factory based on the provided certificates.
* This utility also support an option to enable and disable server hostname verification.
*
* Note: Java use jks (Java KeyStore) format, but openssl usual use pem format. We can convert it by keytool (jdk build-in tool), or use
* BouncyCastle library to handle pem.
*
* The original code is by Sharon Asher (link below). I have modified it to use a newer version of the BouncyCastle Library (v1.68)
* Add below dependencies to work with this util.
* org.bouncycastle:bcpkix-jdk15on:1.68
@HanSolo
HanSolo / Detector.java
Last active August 30, 2023 23:42
Detector: A plain Java class that offers some utility methods to detect dark theme on MacOS and Windows
import javafx.scene.paint.Color;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@marttp
marttp / App.js
Created February 9, 2020 05:06
Example of Server-Sent Events in Client (React)
import React, { useState } from "react";
import axios from 'axios';
import "./App.css";
export default function App() {
const [process, setProcess] = useState({});
const [message, setMessage] = useState({});
const [listening, setListening] = useState(false);
const statusMessage = {
@Eng-Fouad
Eng-Fouad / java.md
Created August 29, 2017 01:33
Generating ECPrivateKey and ECPublicKey

Generate keys:

KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
kpg.initialize(new ECGenParameterSpec("secp521r1"), new SecureRandom());
KeyPair keyPair = kpg.generateKeyPair();
ECPrivateKey privateKey = (ECPrivateKey) keyPair.getPrivate();
ECPublicKey publicKey = (ECPublicKey) keyPair.getPublic();
byte[] privateKeyS = privateKey.getS().toByteArray();
byte[] publicKeyX = publicKey.getW().getAffineX().toByteArray();

byte[] publicKeyY = publicKey.getW().getAffineY().toByteArray();

@thomasdarimont
thomasdarimont / KeycloakAdminClientExample.java
Last active July 18, 2024 19:18
Using Keycloak Admin Client to create user with roles (Realm and Client level)
package demo.plain;
import org.keycloak.OAuth2Constants;
import org.keycloak.admin.client.CreatedResponseUtil;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.admin.client.resource.UsersResource;
import org.keycloak.representations.idm.ClientRepresentation;
@dain
dain / Directions for creating PEM files
Last active October 16, 2023 09:11
Create Java KeyStore from standard PEM encoded private key and certificate chain files
# To regenerate the test key and certificates
# Generate an RSA private key and convert it to PKCS8 wraped in PEM
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform pem -outform pem -nocrypt -out rsa.key
# Generate a certificate signing request with the private key
openssl req -new -key rsa.key -out rsa.csr
# Sign request with private key
openssl x509 -req -days 10000 -in rsa.csr -signkey rsa.key -out rsa.crt
@define-private-public
define-private-public / HttpServer.cs
Last active July 24, 2024 05:35
A Simple HTTP server in C#
// Filename: HttpServer.cs
// Author: Benjamin N. Summerton <define-private-public>
// License: Unlicense (http://unlicense.org/)
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Threading.Tasks;
@SurealCereal
SurealCereal / bootgui
Created June 19, 2015 13:30
Bash script to enable/disable the GUI on boot for Ubuntu Mate. Tested on Ubuntu Mate 15.04 on a Raspberry Pi 2 B.
#!/bin/bash
# Call with either enable or disable as first parameter
if [[ "$1" == 'enable' || "$1" == 'disable' ]]; then
sudo systemctl set-default multi-user.target --force
sudo systemctl $1 lightdm.service --force
sudo systemctl $1 graphical.target --force
sudo systemctl $1 plymouth.service --force
else
echo Call with either "enable" or "disable" as first parameter.
fi
@InfoSec812
InfoSec812 / gist:a45eb3b7ba9d4b2a9b94
Last active November 3, 2022 16:56
SSL Config Example For Vert.x 3.0.0
package com.zanclus.socialshell;
import com.zanclus.socialshell.utils.AbstractLoggingVerticle;
import static io.vertx.ext.auth.shiro.LDAPAuthRealmConstants.*;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Verticle;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.json.JsonObject;
@skrb
skrb / ComplexAnimation.java
Created June 12, 2012 12:38
JavaFX Animation Sample
package net.javainthebox.jfx.animation;
import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.event.ActionEvent;