Skip to content

Instantly share code, notes, and snippets.

View exceedsystem's full-sized avatar

Y.Sakamoto exceedsystem

View GitHub Profile
@exceedsystem
exceedsystem / OpenAI.js
Last active March 23, 2024 07:58
Sample of a VSCode Macros to call OpenAI (ChatGPT) from VSCode
// License:MIT
// https://www.exceedsystem.net/2023/04/07/vscode-macros-macro-that-calls-chat-gpt-api-from-vscode
const vscode = require('vscode');
const process = require('process');
const { Configuration, OpenAIApi, OpenAI } = require('openai');
// Completion API result class
class RunCompletionResult {
constructor(status, content, model, cost) {
this.status = status;
@exceedsystem
exceedsystem / KanaToHepburnRomaji.js
Created February 23, 2024 03:45
Convert Kana to Hepburn romanization
const vscode = require('vscode');
/**
* マクロコンフィギュレーション(環境に合わせてお好みで設定)
*/
module.exports.macroCommands = {
'カナ→ヘボン式ローマ字': {
no: 1,
func: toHepburn
},
@exceedsystem
exceedsystem / simple_totp_client.cs
Last active October 18, 2023 16:35
A simple example of implementing TOTP in C#
// https://www.exceedsystem.net/2021/10/04/how-to-implement-otp-in-csharp-so-easy/
// License:MIT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Threading;
namespace _2FAS
@exceedsystem
exceedsystem / UserDirCleaner.cs
Created August 19, 2023 22:23
Sample tool for cleaning up the temporary directory under the Windows user directory in .NET 7(C#)
amespace UserTempCleaner
{
internal class Program
{
// Threshold of elapsed time since the last use of the file/folder
private const int ELAPSED_HOURS = 168;
private static readonly string LOG_FILE = $"UserTempCleaner_{DateTime.Now:yyyyMMddHHmmss}.log";
private static void Main(string[] args)
@exceedsystem
exceedsystem / StdDevExtension.cs
Last active November 21, 2022 08:57
Samples of calculating standard deviation in .NET(C#/VB.NET).
static class Extensions
{
public static double StdDev(this IEnumerable<double> src)
{
IList<double> lst = src is IList<double> ? (IList<double>)src : src.ToArray();
int n = lst.Count();
double ave = lst.Average();
double s = 0;
for (int i = 0; i < n; ++i)
s = s + (lst[i] - ave) * (lst[i] - ave);
@exceedsystem
exceedsystem / TorchSharpTest220910.cs
Last active September 12, 2022 10:05
How to implement XOR gate nural network with torch in .NET 6
// EXCEEDSYSTEM Sample of the XOR gate neural network with the TorchSharp
// https://www.exceedsystem.net/2022/09/12/how-to-implement-xor-gate-neural-network-with-torch-in-dotnet-6
// License: MIT
using TorchSharp;
using static TorchSharp.torch;
using static TorchSharp.torch.nn;
using static TorchSharp.torch.nn.functional;
// Fix the random number seed to be used for weight and bias
torch.random.manual_seed(1);
@exceedsystem
exceedsystem / FirestoreTest220903.cs
Created September 4, 2022 06:23
Cloud Firestore auth and CRUD sample in C#(.NET 6)
using Firebase.Auth;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Firestore;
using Google.Cloud.Firestore.V1;
// Create a Firebase authentication provider with your Firebase project API key
var fbAuthProv = new FirebaseAuthProvider(new FirebaseConfig("{API key for your Firebase project}"));
try
@exceedsystem
exceedsystem / vscmacros_launc_bash.js
Created December 21, 2020 12:15
An example of 'Bash launcher' macro for VSCodeMacros extension
// [VSCode Macros] extension
// https://marketplace.visualstudio.com/items?itemName=EXCEEDSYSTEM.vscode-macros
const vscode = require('vscode');
/**
* Macro configuration
*/
module.exports.macroCommands = {
LaunchBash: {
no: 1,
@exceedsystem
exceedsystem / vscmacros_remove_duplicate_lines.js
Created December 21, 2020 12:17
An example of 'Remove Duplicate Lines' macro for VSCodeMacros extension
// [VSCode Macros] extension
// https://marketplace.visualstudio.com/items?itemName=EXCEEDSYSTEM.vscode-macros
const vscode = require('vscode');
/**
* Macro configuration
*/
module.exports.macroCommands = {
RemoveDuplicateLines: {
no: 1,
@exceedsystem
exceedsystem / insert_random_id_using_node.js
Last active July 3, 2022 23:07
An example of 'Insert Random ID using Node.js' macro for VSCodeMacros extension
// [VSCode Macros] extension
// https://marketplace.visualstudio.com/items?itemName=EXCEEDSYSTEM.vscode-macros
// License:MIT
const vscode = require('vscode');
const crptrndstr = require('crypto-random-string');
module.exports.macroCommands = {
InsertRandomID: {
no: 1,
func: insertRandomId,