Skip to content

Instantly share code, notes, and snippets.

View akunzai's full-sized avatar

Charley Wu akunzai

  • Taipei,Taiwan
  • 17:27 (UTC +08:00)
  • X @akunzai
View GitHub Profile
@akunzai
akunzai / Ciphers.java
Created December 14, 2016 10:19
List JVM Ciphers
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import javax.net.ssl.SSLServerSocketFactory;
public class Ciphers
{
public static void main(String[] args)
throws Exception
{
@akunzai
akunzai / sqlite_backup.ps1
Last active August 30, 2019 10:43
SQLite Backup Rotation Script
# usage: powershell -ExecutionPolicy Bypass -file .\sqlite_backup.ps1 -dbFile .\tobackup.db3 -backupDir .\backup
# please make sure sqlite3.exe can be found in $PATH or specify it by -sqliteExe parameter
Param(
# https://chocolatey.org/packages/sqlite.shell
[string]$sqliteExe = "sqlite3.exe",
[Parameter(Mandatory = $true)]
[string]$dbFile,
# default same as dbFile's directory
[string]$backupDir = "",
# [default|fullday|fulltime]
@akunzai
akunzai / FileProviderExtensions.cs
Last active November 28, 2022 20:38
Microsoft.Extensions.FileProviders Extension Methods
using System;
using System.IO;
using System.Text.Json;
namespace Microsoft.Extensions.FileProviders;
public static class FileProviderExtensions
{
public static Stream ReadAsStream(this IFileProvider fileProvider, string path)
{
@akunzai
akunzai / ExpressionExtensions.cs
Created November 17, 2017 18:01
Combine two Linq predicate expression
namespace System.Linq.Expressions
{
public static class ExpressionExtensions
{
public static Expression<Func<T,bool>> And<T>(this Expression<Func<T,bool>> left, Expression<Func<T, bool>> right)
{
if (left == null) return right;
var and = Expression.AndAlso(left.Body, right.Body);
return Expression.Lambda<Func<T, bool>>(and, left.Parameters.Single());
}
@akunzai
akunzai / LargeFormUrlEncodedContent.cs
Last active December 29, 2017 07:49
alternative FormUrlEncodedContent that support large context
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Text;
namespace System.Net.Http
{
/// <summary>
/// alternative <see cref="FormUrlEncodedContent"/> implementation that support large context
/// to prevent <see cref="UriFormatException"/> Invalid URI: The Uri string is too long. error
/// </summary>
#!/bin/bash
################################################################################
# FUNCTIONS
################################################################################
# 1. Check required system tools
_check_installed_tools() {
local missed=""
@akunzai
akunzai / .editorconfig
Last active July 7, 2023 15:02
My Editor Config
# http://EditorConfig.org
# top-most EditorConfig file
root = true
# Default settings:
# A newline ending every file
# Use 4 spaces as indentation
[*]
charset = utf-8
@akunzai
akunzai / ClearSQLiteCommandConnectionHelper.cs
Last active September 8, 2021 13:47
Fixes System.Data.SQLite Close() not releasing database file , see https://stackoverflow.com/a/38268171
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
public static class ClearSQLiteCommandConnectionHelper
{
private static readonly object lockObject = new object();
private static readonly List<SQLiteCommand> OpenCommands = new List<SQLiteCommand>();
@akunzai
akunzai / Microsoft.PowerShell_profile.ps1
Last active September 7, 2024 12:20
My PowerShell profile
# https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_profiles
# PowerShell < 6 on Windows: $Home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
# PowerShell >= 6 on Windows: $Home\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
# PowerShell on Linux/macOS: ~/.config/powershell/Microsoft.PowerShell_profile.ps1
# https://learn.microsoft.com/dotnet/core/tools/dotnet-environment-variables#dotnet_cli_ui_language
$env:DOTNET_CLI_UI_LANGUAGE = 'en-us'
# https://github.com/PowerShell/PSReadLine
if (Get-Command 'Set-PSReadlineKeyHandler' -ErrorAction SilentlyContinue) {
@akunzai
akunzai / prop2xml.groovy
Last active March 12, 2019 08:46
Java Properties Converter
if (args.length == 0) {
println("Usage: groovy prop2xml.groovy messages.(properties|xml) [format]")
println("read from STDIN: groovy prop2xml.groovy - [format]")
System.exit(0)
}
def input = args[0] == '-'
? System.in
: new File(args[0]).newInputStream()
def format = args.size() > 1