Skip to content

Instantly share code, notes, and snippets.

View xbotter's full-sized avatar
:octocat:

xbotter xbotter

:octocat:
  • China , ShangHai
  • 20:59 (UTC +08:00)
View GitHub Profile
@xbotter
xbotter / dotnet-ef-migration-script.ps1
Created November 22, 2023 08:50
Generate dotnet ef migration scripts for all migrations that don't have a script yet
# build the latest code
dotnet build
# get all migration ids and store them in an array
$migrations = dotnet ef migrations list --no-build --no-connect --json | ConvertFrom-Json
# iterate through the array
for ($i = 0; $i -lt $migrations.Length; $i++) {
# get the current migration id

.NET 软件开发工程师

  • 岗位职责:
    1、负责编写公司应用层逻辑、做一些轻量级的数据分析。
    2、负责所属模块的代码开发、调试与维护工作;
    3、参与公司产品的架构优化,性能优化并辅助其他模块进行技术实现;
    4、协助并完成其他各类技术开发任务。

  • 岗位要求:
    1、计算机或者相关专业,统招全日制本科及以上学历。

@xbotter
xbotter / MockHttpClient.cs
Created May 19, 2023 06:10
如何Mock一个HttpClient
var httpClientMock = new Mock<HttpClient>();
// Set up the SendAsync method to return a desired response
httpClientMock
.Setup(x => x.SendAsync(It.IsAny<HttpRequestMessage>(), CancellationToken.None))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));
// Set up the SendAsync method to match a specific URL and return a desired response
httpClientMock
.Setup(x => x.SendAsync(It.Is<HttpRequestMessage>(req => req.RequestUri.AbsoluteUri == "https://example.com/api/data"), CancellationToken.None))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("Mocked response") });
@xbotter
xbotter / AzureAppServiceMysqlConnectionParser.cs
Created December 18, 2022 02:31
Parse Azure App Service MYSQLCONNSTR to EF connectionstring
public class AzureAppServiceMysqlConnectionParser
{
const string Database = nameof(Database);
const string Server = "Data Source";
const string UId = "User Id";
const string Pwd = "Password";
// example: Database={database};Data Source={host}:{port};User Id={username};Password={password}
public static string Parse(string mysqlconnstr) {
@xbotter
xbotter / Aes.cs
Created September 3, 2021 11:12
天瑞融通 API接口使用到的C#加密方法
private static string AesEncrypt(string cleartext, string password)
{
var aes = Aes.Create();
var sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(password));
var rd = sha1.ComputeHash(hash);
var keyArray = rd.Take(16).ToArray();
aes.Key = keyArray;
aes.Mode = CipherMode.ECB;
var byteBuff = Encoding.UTF8.GetBytes(cleartext);
@xbotter
xbotter / clear-none-images.ps1
Created March 10, 2021 02:40
docker scripts
docker images | findstr '<none>' | ForEach-Object{$_.Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[2];}| ForEach-Object{docker rmi $_}
public interface ITimerDataSource
{
TimerTask LastTask();
void RemoveTask(string taskid);
void Insert(TimerTask task);
}
@xbotter
xbotter / md5.cs
Created May 11, 2020 05:31
C# MD5 String
public static string GetMd5String(string input)
{
using (MD5 md5Hash = MD5.Create())
{
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
@xbotter
xbotter / index.js
Created March 16, 2020 05:58
create or update querystring
function paramReplace(uri, key, value) {
// Find the param with regex
// Grab the first character in the returned string (should be ? or &)
// Replace our href string with our new value, passing on the name and delimeter
var re = new RegExp("[\\?&]" + key + "=([^&#]*)");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
var matches = re.exec(uri);
var newUri;
if (matches === null) {
@xbotter
xbotter / PartialFunction.cs
Created August 16, 2017 01:27
C# Partial Function
public static class PartialFunction
{
public static Func<T1,Func<T2,TResult>> Curry<T1,T2,TResult>(Func<T1,T2,TResult> func) => arg1 =>arg2=>func(arg1,arg2);
public static Func<T1,Func<T2,Func<T3,TResult>>> Curry<T1,T2,T3,TResult>(Func<T1,T2,T3,TResult> func) => arg1=>arg2=>arg3=>func(arg1,arg2,arg3);
public static Func<T1,Func<T2,Func<T3,Func<T4,TResult>>>> Curry<T1,T2,T3,T4,TResult>(Func<T1,T2,T3,T4,TResult> func) => arg1=>arg2=>arg3=>arg4=>func(arg1,arg2,arg3,arg4);
public static Func<T1,Func<T2,Func<T3,Func<T4,Func<T5,TResult>>>>> Curry<T1,T2,T3,T4,T5,TResult>(Func<T1,T2,T3,T4,T5,TResult> func) => arg1=>arg2=>arg3=>arg4=>arg5=>func(arg1,arg2,arg3,arg4,arg5);
public static Func<T1,Func<T2,Func<T3,Func<T4,Func<T5,Func<T6,TResult>>>>>> Curry<T1,T2,T3,T4,T5,T6,TResult>(Func<T1,T2,T3,T4,T5,T6,TResult> func) => arg1=>arg2=>arg3=>arg4=>arg5=>arg6=>func(arg1,arg2,arg3,arg4,arg5,arg6);
public static Func<T1,Func<T2,Func<T3,Func<T4,Func<T5,Func<T6,Func<T7,TResult>>>>>>> Curry<T1,T2,T3,T4,T5,