Skip to content

Instantly share code, notes, and snippets.

@Crydust
Crydust / XmlStax.java
Last active August 30, 2023 14:03
Read xml using stax api in java
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.EndElement;

Git worktree

# clone the repo, but switch it to a dummybranch so other worktrees can checkout the main branch
git clone --no-checkout URL_HERE repo.git
cd repo.git
git switch -c dummy

# add a worktree
git worktree add ../repo_main main
@Crydust
Crydust / my-winutil.ps1
Created February 18, 2023 16:44
remove junk from windows 10
Write-Host "Creating Restore Point in case something bad happens"
Enable-ComputerRestore -Drive "$env:SystemDrive"
Checkpoint-Computer -Description "RestorePoint1" -RestorePointType "MODIFY_SETTINGS"
#WPFEssTweaksDVR
If (!(Test-Path "HKCU:\System\GameConfigStore")) {
New-Item -Path "HKCU:\System\GameConfigStore" -Force
}
Set-ItemProperty -Path "HKCU:\System\GameConfigStore" -Name "GameDVR_DXGIHonorFSEWindowsCompatible" -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\System\GameConfigStore" -Name "GameDVR_HonorUserFSEBehaviorMode" -Type DWord -Value 1
@Crydust
Crydust / transparent-pixel.html
Created February 8, 2023 13:13
transparent pixel
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="/>
@Crydust
Crydust / LogHttpServletRequest.java
Last active February 7, 2023 10:26
log HttpServletRequest
sb.append("*** request.getMethod() = ").append(request.getMethod()).append("\n");
sb.append("*** request.getContextPath() = ").append(request.getContextPath()).append("\n");
sb.append("*** request.getRequestURI() = ").append(request.getRequestURI()).append("\n");
sb.append("*** request.getServletPath() = ").append(request.getServletPath()).append("\n");
sb.append("*** request.getPathInfo() = ").append(request.getPathInfo()).append("\n");
final ArrayList<String> headerNames = Collections.list(request.getHeaderNames());
for (final String headerName : headerNames) {
final ArrayList<String> headers = Collections.list(request.getHeaders(headerName));
for (int i = 0; i < headers.size(); i++) {
final String header = headers.get(i);
@Crydust
Crydust / gist:09a550e27d2b5cef79bcbe9560a5e522
Created October 4, 2022 19:08
Trim video and convert to codec known by powerpoint
ffmpeg -i input.webm -ss 00:02:11 -t 00:01:40 -c:v libx264 -c:a aac output.mp4
# PowerPoint supports .mp4 files encoded with H.264 video and AAC audio
# -ss = start time
# -t = duration (after start time)
# -c:v = video codec for output
# -c:a = audio codec for output
@Crydust
Crydust / _ValidationScriptsPartial.cshtml
Last active March 28, 2022 17:38
dotnet webapp validation config
<script src="~/lib/jquery-validate/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
@if (",".Equals(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
{
<script>
// decimal separator comma instead of point
jQuery.extend(jQuery.validator.methods, {
number: function(value, element) {
return this.optional(element) || /^-?\d+(?:,\d+)?$/.test(value);
@Crydust
Crydust / LoggingMap
Last active February 25, 2021 09:58
a logging map which can replace a HashMap and will log when it is being accessed or altered
import static java.util.stream.Collectors.toUnmodifiableSet;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
@Crydust
Crydust / ClientApp.java
Created January 24, 2021 19:15
Java socket server and client
package spike;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Timer;
import static java.nio.charset.StandardCharsets.UTF_8;