備忘録

備忘録

Visual StudioのIntelliCodeをオフにする方法

Ⅰ. はじめに

タイトルの通り「Visual StudioのIntelliCodeをオフにする方法」です。

Ⅱ. 手順

1. VisualStudioのツール→オプションをクリック
2. 「無効」に設定する

f:id:kagasu:20220205041054p:plain

実行結果

設定前 f:id:kagasu:20220205041116p:plain
設定後 f:id:kagasu:20220205041136p:plain

C#でLZ4を利用して圧縮展開する方法

Ⅰ. はじめに

タイトルの通り「C#でLZ4を利用して圧縮展開する方法」です。

Ⅱ. 手順

1. 必要なパッケージをNuGetからインストールする
dotnet add package K4os.Compression.LZ4 --version 1.3.5
2. サンプルプログラムを書く

Program.cs

using K4os.Compression.LZ4;

var originalBytes = Encoding.UTF8.GetBytes("hello world");

// 圧縮
var encodedBytes = new byte[256];
var length = LZ4Codec.Encode(originalBytes, encodedBytes);
encodedBytes = encodedBytes.Take(length).ToArray();
Console.WriteLine(BitConverter.ToString(encodedBytes));

// 展開
var decodedBytes = new byte[256];
length = LZ4Codec.Decode(encodedBytes, decodedBytes);
decodedBytes = decodedBytes.Take(length).ToArray();
Console.WriteLine(BitConverter.ToString(decodedBytes));

実行結果

B0-68-65-6C-6C-6F-20-77-6F-72-6C-64
68-65-6C-6C-6F-20-77-6F-72-6C-64

.NET に関する記事まとめ

.NET 6

// https://docs.microsoft.com/ja-jp/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-6.0
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/todos/{id:int}", (int id) => db.Todos.Find(id));
app.MapGet("/todos/{text}", (string text) => db.Todos.Where(t => t.Text.Contains(text));
app.MapGet("/posts/{slug:regex(^[a-z0-9_-]+$)}", (string slug) => $"Post {slug}");

app.Run();

puppeteerでproxyを利用する方法

Ⅰ. はじめに

タイトルの通り「puppeteerでproxyを利用する方法」です。

Ⅱ. 方法1(起動引数を設定する)

  • この方法は認証無しのHTTP Proxyのみ設定出来ます

手順

1. サンプルプログラムを書く
const browser = await puppeteer.launch({
  args: [
    '--proxy-server=127.0.0.1:8080'
  ]
});

実行結果

省略

Ⅲ. 方法2(ライブラリを利用する方法)

手順

1. 必要なライブラリをインストールする
npm i puppeteer
npm i puppeteer-proxy

# HTTP, HTTPS
npm install https-proxy-agent

# SOCKS5
npm i socks-proxy-agent
2. サンプルプログラムを書く

index.js

const puppeteer = require('puppeteer');
const { proxyRequest } = require('puppeteer-proxy');
const HttpsProxyAgent = require('https-proxy-agent');
const SocksProxyAgent = require('socks-proxy-agent');

(async () => {
  const browser = await puppeteer.launch({ defaultViewport: null, headless: false, slowMo: 300 })
  const page = await browser.newPage()

  const agent = {
    http: new HttpsProxyAgent('http://127.0.0.1:3128'),
    https: new HttpsProxyAgent('http://127.0.0.1:3128'),
    // http: new HttpsProxyAgent('http://user:pass@127.0.0.1:3128'),
    // https: new HttpsProxyAgent('http://user:pass@127.0.0.1:3128'),
  }

  /*
  const agent = {
    http: new SocksProxyAgent('socks5://127.0.0.1:1080'),
    https: new SocksProxyAgent('socks5://127.0.0.1:1080'),
    // http: new SocksProxyAgent('socks5://user:pass@127.0.0.1:1080'),
    // https: new SocksProxyAgent('socks5://user:pass@127.0.0.1:1080'),
  }
  */

  await page.setRequestInterception(true);
  page.on('request', async (request) => {
    await proxyRequest({
      agent,
      page,
      request,
    });
  });

  await page.goto('https://api.ipify.org/')
})()

実行結果

省略

C#でJavaScriptを実行する方法

Ⅰ. はじめに

タイトルの通り「C#JavaScriptを実行する方法」です。

Ⅱ. 手順

1. 必要なパッケージをインストールする
Install-Package Microsoft.ClearScript
2. サンプルプログラムを書く
using Microsoft.ClearScript.V8;

using var engine = new V8ScriptEngine();
engine.AddHostType("Console", typeof(Console));
engine.Execute("Console.WriteLine('hello world')");

engine.AddHostObject("random", new Random());
engine.Execute("Console.WriteLine(random.Next(0, 10))");

engine.Execute("var result = 1 + 1");
Console.WriteLine(engine.Script.result);

engine.Execute("function sum (x, y) { return x + y }");
Console.WriteLine(engine.Script.sum(1, 2));

engine.ExecuteCommand("var user = { id: 1, name: 'tanaka' }");
Console.WriteLine(engine.Script.user.id);
Console.WriteLine(engine.Script.user.name);

実行結果

hello world
4
2
3
1
tanaka