Skip to content

Instantly share code, notes, and snippets.

@destan
destan / ParseRSAKeys.java
Last active March 29, 2024 10:43
Parse RSA public and private key pair from string in Java
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
@destan
destan / text2png.py
Last active January 10, 2024 06:32
Python text to image (png) conversion with automatic new line calculation
# coding=utf8
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
def text2png(text, fullpath, color = "#000", bgcolor = "#FFF", fontfullpath = None, fontsize = 13, leftpadding = 3, rightpadding = 3, width = 200):
REPLACEMENT_CHARACTER = u'\uFFFD'
NEWLINE_REPLACEMENT_STRING = ' ' + REPLACEMENT_CHARACTER + ' '
@destan
destan / SpringSecurity.ascii
Last active May 15, 2022 01:35
Spring Security cheetsheet
https://gist.asciidoctor.org/?7454349eb96c97529f82b23988094af4[View this document rendered]
## SecurityContextHolder
* Holds the details of the authentication (authenticated user)
* By default the SecurityContextHolder uses a ThreadLocal to store these details
** SecurityContextHolder.MODE_THREADLOCAL `default`
** SecurityContextHolder.MODE_INHERITABLETHREADLOCAL
** SecurityContextHolder.MODE_GLOBAL
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.util.TraceClassVisitor;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import static org.objectweb.asm.Opcodes.ASM9;
@destan
destan / Quine.java
Last active December 8, 2020 08:02
Simple Java quine, self replicating (self copying) Java code, with text blocks. This code can be run with Java 15+ or Java 13+ with special flags. License is public domain, no rights reserved.
public class Quine {
public static void main(String[] args) {
String textBlockQuotes = new String(new char[]{'"', '"', '"'});
char newLine = 10;
String source = """
public class Quine {
public static void main(String[] args) {
String textBlockQuotes = new String(new char[]{'"', '"', '"'});
char newLine = 10;
String source = %s;
@destan
destan / slugify_tr.js
Last active October 4, 2019 12:25 — forked from muratcorlu/slugify_tr.js
slugify_tr slugify tr js
/**
* Metni url'de kullanılabilir hale çevirir. Boşluklar tireye çevrilir,
* alfanumerik olmayan katakterler silinir.
*
* Transform text into a URL path slug(with Turkish support).
* Spaces turned into dashes, remove non alnum
*
* @param string text
*/
slugify = function(text) {
@destan
destan / index.html
Last active October 4, 2019 12:23 — forked from darwin/index.html
http://cmx.io/#09e3f209fdec1b8d7a77 java VS php VS ruby karikatur
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css"/>
<script src="http://cmx.io/v/0.1/cmx.js"></script>
<body>
<scene id="scene1">
<label t="translate(0,346)">
<tspan x="0" y="0em">In Java world</tspan>
</label>
<actor t="translate(131,49)" pose="-11,9|-5,117|-11,99|-11,89|-11,79|-11,59|-16,34|-21,9|-6,34|-1,9|-18,79|-40,79|-6,79|-1,59">
@destan
destan / JavaBeginnerQuertionTr.md
Last active October 4, 2019 12:20
temel java inheritance sorusu

Aşağıdaki kodu inceleyiniz:

public abstract class Animal {...}

public class Human extends Animal implements Omnivore {...}

public class Deer extends Animal implements Herbivore {...}