Skip to content

Instantly share code, notes, and snippets.

View mmdemirbas's full-sized avatar

Muhammed Demirbaş mmdemirbas

View GitHub Profile
@mmdemirbas
mmdemirbas / CombineIntoPDF.java
Last active August 17, 2023 10:38
Combine multiple images into a single PDF file using Apache PDFBox 2.0.1
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@mmdemirbas
mmdemirbas / MultiDatePicker.java
Last active May 31, 2022 22:27
JavaFX Multiple Dates Picker
package com.mmdemirbas.lab;
/**
* Created by md on 5.04.2016.
*/
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
@mmdemirbas
mmdemirbas / LogbackUtils.java
Last active November 26, 2021 11:41
Changing log level for logback-classic using reflection if it is present in the classpath without depending to the JAR.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.MessageFormat;
/**
* Contains methods to access and manipulate logback framework dynamically at run-time. Here 'dynamically' means without
* referencing the logback JAR, but using it if found in the classpath.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="main" trace="disable">
<in>
<log level="headers">
<property name="?" value="[main] in: started"/>
<property name="To" expression="get-property('To')"/>
<property name="PAYLOAD" expression="/*"/>
</log>
<script language="js"><![CDATA[
mc.setPayloadXML(<greeting>Hello World</greeting>);
]]></script>
@mmdemirbas
mmdemirbas / main.xml
Created April 8, 2013 06:45
WSO2 ESB + ClientAccesPolicy.xml + CrossDomain.xml Link: http://www.mmdemirbas.com/2013/04/wso2-esb-clientaccespolicyxml.html
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="main" trace="disable">
<in>
<log level="headers">
<property name="?" value="[main] in: started"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="To"
expression="get-property('To')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="PAYLOAD" expression="/*"/>
</log>
@mmdemirbas
mmdemirbas / battery.ps1
Created March 27, 2013 11:21
PowerShell script to help to keep laptop battery level in the specified range. Not automatically! You need to plug-in or unplug cable when you hear alert sound :) See: http://www.mmdemirbas.com/2013/03/monitor-remaining-battery-level-using.html
#########################################################################
# #
# Script to check battery state periodically and alert if it is #
# going to outside of the desired range (%40-%80) by default. #
# #
# Usage: #
# #
# # To alert if x<=40 or x>=80, and check each 15 sec #
# #
# .\battery.ps1 40 80 15 #
@mmdemirbas
mmdemirbas / set-ntfs-ro.ps1
Created March 23, 2013 20:54
PowerShell script to set or clear NTFS read-only flag of a volume by volume label
#########################################################################
# #
# Script to set or clear read-only flag of an NTFS volume. #
# #
# Usage: .\set-ntfs-ro.ps1 set "MY DISK LABEL" #
# .\set-ntfs-ro.ps1 clear "MY DISK LABEL" #
# #
# Author: Muhammed Demirbas, mmdemirbas at gmail dot com #
# Date : 2013-03-23 #
# #
@mmdemirbas
mmdemirbas / listen.bat
Created October 8, 2012 13:29
Batch script to execute a given command repeatedly. Waits specified amount of time between two executions.
@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: This script executes given command repeatedly.
:: Waits specified amount of time between two executions.
:: First parameter MUST be sleep time.
:: Rest of the parameters will be executed as a command.
:: This script relies on sleep command from GnuWin32 package.
::
@mmdemirbas
mmdemirbas / grub-use-saved.sh
Created October 8, 2012 09:33
Configures grub to set last used entry as default automatically in each boot
# @author: mmdemirbas@gmail.com
filename=/etc/default/grub
# Replace GRUB_DEFAULT value to 'saved'
echo :: Setting GRUB_DEFAULT=saved
sudo sed -i 's/GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/g' $filename
# Append GRUB_SAVEDEFAULT=true after deleting old GRUB_SAVEDEFAULT's
echo :: Setting GRUB_SAVEDEFAULT=true
@mmdemirbas
mmdemirbas / beep.bat
Created September 23, 2012 10:58
Windows batch file to generate a beep sound after a certaion amount of time.
:: usage:
:: beep -- beeps immediately
:: beep 1 -- beeps after 1 sec
:: beep 1:2 -- beeps after 1 min, 2 sec
:: beep 1:2:3 -- beeps after 1 hour, 2 min, 3 sec
:: beep 1:2:3:4 -- beeps after 1 day, 2 hours, 3 min, 4 sec
::
:: invalid usages:
:: beep 1::2
:: beep :1