Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Tinkering

Vivek Singh viveksb007

💻
Tinkering
View GitHub Profile
View SegmentTree.java
import java.util.Arrays;
public class SegmentTree {
private final MergeFunction<Integer, Integer, Integer> mergeFunction;
private final Integer[] tree;
public SegmentTree(Integer[] arr, MergeFunction<Integer, Integer, Integer> mergeFunction) {
tree = new Integer[findArraySizeToRepresentTree(arr.length)];
this.mergeFunction = mergeFunction;
View IsPerfectSquare.java
import java.util.function.Predicate;
public class IsPerfectSquare implements Predicate<Integer> {
@Override
public boolean test(Integer x) {
return Math.floor(Math.sqrt(x)) == Math.sqrt(x);
}
}
View CustomLevel.java
// Defining Custom log level in code
Level IMPORTANT = Level.forName("IMPORTANT", 250);
Logger logger = LogManager.getLogger();
logger.log(IMPORTANT, "Log Message");
View SetRootLevel.java
Configurator.setRootLevel(Level.getLevel("IMPORTANT"));
logger.log(Level.getLevel("IMPORTANT"), "Log Message");
// After all important logging, you can set logging root level back to your default
Configurator.setRootLevel(Level.getLevel("ERROR"));
View log4j2.properties
customLevel.CUSTOM=450
customLevel.IMPORTANT=250
rootLogger.level=IMPORTANT
View wr_send_file.py
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['DOWNLOAD_FOLDER'], filename, as_attachment=True)
View wr_process.py
from PyPDF2 import PdfFileReader, PdfFileWriter
DOWNLOAD_FOLDER = os.path.dirname(os.path.abspath(__file__)) + '/downloads/'
app.config['DOWNLOAD_FOLDER'] = DOWNLOAD_FOLDER
def process_file(path, filename):
remove_watermark(path, filename)
def remove_watermark(path, filename):
View wr_index.py
from flask import Flask, request, redirect, url_for, render_template, send_from_directory
from werkzeug.utils import secure_filename
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if 'file' not in request.files:
print('No file attached in request')
return redirect(request.url)
file = request.files['file']
View wr_allowed_extension.py
ALLOWED_EXTENSIONS = {'pdf'}
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
View wr_index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Watermark Remover</title>
</head>
<body>
<div align="center">
<h1>Cam-Scanner Watermark Remover</h1>
<h2>Upload new File</h2>