Skip to content

Instantly share code, notes, and snippets.

View SharkFourSix's full-sized avatar
💭
I may be slow to respond.

SharkFourSix

💭
I may be slow to respond.
View GitHub Profile
@SharkFourSix
SharkFourSix / AntiXsrfCookie.java
Last active July 2, 2019 15:14
Anti-XSRF Cookies in Spark Java using 'SameSite' flag
import javax.servlet.http.Cookie;
import java.text.DateFormat;
import java.util.Date;
import java.util.TimeZone;
public final class AntiXsrfCookie extends Cookie {
private static final String SAME_SITE_LAX = "Lax";
private static final String SAME_SITE_STRICT = "Strict";
@SharkFourSix
SharkFourSix / HttpsRedirector.java
Last active July 2, 2019 15:15
Spark Java HTTP to HTTPS redirector
import java.io.Closeable;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Set;
public final class HttpsRedirector {
@SharkFourSix
SharkFourSix / UrlUtil.java
Created August 11, 2021 15:04
URL Query Parameter Manipulator: Add/Remove Query Parameters
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
public class UrlUtil {
private final URL url;
private final Map<String, List<String>> parameters;
public UrlUtil(String url) throws MalformedURLException {
this.url = new URL(url);
@SharkFourSix
SharkFourSix / forcefully-delete-docker-images.sh
Last active July 30, 2022 02:50
Delete docker images using image ID
for ID in $(sudo docker images --format "{{.ID}}" --filter "dangling=true")
do
echo "forcefully delete image $ID"
sudo docker rmi -f $ID
done
sudo docker images
@SharkFourSix
SharkFourSix / httpstatus.js
Created February 20, 2023 22:17
httpstatus.js
(function umd(root, factory) {
root.httpStatus = factory();
})(this, function () {
class StatusEvaluator {
constructor(code) {
this.code = code;
this.map = {};
this.ow = null;
}
@SharkFourSix
SharkFourSix / scratch-redis.Dockerfile
Last active October 10, 2023 16:49
Small docker image file for containerizing redis binary.
# syntax=docker/dockerfile:experimental
# Build staticly linked version of redis
FROM alpine:3.18.4 as redis-builds
ADD https://download.redis.io/redis-stable.tar.gz .
ADD https://liquidtelecom.dl.sourceforge.net/project/tcl/Tcl/8.6.13/tcl8.6.13-src.tar.gz .
RUN set -ex && \
apk add --no-cache make && \
apk add --no-cache gcc musl-dev
RUN tar -xzf redis-stable.tar.gz \
@SharkFourSix
SharkFourSix / pgsql_backup.sh
Created June 11, 2024 05:41 — forked from sirbrillig/pgsql_backup.sh
Postgresql daily backup script.
#!/bin/bash
#
# Backup a Postgresql database into a daily file.
#
BACKUP_DIR=/pg_backup
DAYS_TO_KEEP=14
FILE_SUFFIX=_pg_backup.sql
DATABASE=
USER=postgres