Skip to content

Instantly share code, notes, and snippets.

fn main() {
if let Err(e) = catr::run() {
eprintln!("{}", e);
std::process::exit(1);
}
}
@ritalin
ritalin / gist:2cda493ce65466789e7df33e1c615eea
Last active January 8, 2024 09:24
LeetCode SQL question #1321
SQLで移動累計と移動平均を求める良問題
https://leetcode.com/problems/restaurant-growth/
Customer table:
+-------------+--------------+--------------+-------------+
| customer_id | name | visited_on | amount |
+-------------+--------------+--------------+-------------+
| 1 | Jhon | 2019-01-01 | 100 |
| 2 | Daniel | 2019-01-02 | 110 |
@ritalin
ritalin / read_input.zig
Last active December 7, 2023 13:50
競プロでよく見かける標準入力からの読み込みの支援方法を考えてみた。
const std = @import("std");
pub fn main() !void {
const count = try input(struct {x: usize}, 12);
for (0..count.x) |_| {
// タプルの分解構文は、0.12.x以降で可能
// 0.11.xの場合、そのままタプルで受ける必要あり
const x, const y = try input(struct { [16:0]u8, usize }, 1024);
std.debug.print("x = {s}, y = {}\n", .{x, y});
@ritalin
ritalin / objc_block_impl_for_zig.md
Last active November 30, 2023 17:54
zig言語でObjective-Cのブロック型を扱うための設計方針

概要

例えば、AppKitNSAlertのメソッド、beginSheetModalForWindowの第二引数はブロック型を要求する。 zig言語によるAppKitのバインディングで、ブロック型を要求するAPIを扱えるようにしたい。

ブロック型の実行

mitchellh/zig-objc (https://github.com/mitchellh/zig-objc) にて、2023-10-21のコミットでブロック型のサポートが追加された。

以下のようなコードを記述することで、実行できることは確認できた。

@ritalin
ritalin / debug_zig_test_vscode-lldb.md
Last active November 5, 2023 04:44
vscode-lldb によるzig言語のunit testのデバッグ
@ritalin
ritalin / Program.cs
Last active June 30, 2022 17:21
Have difference results, why?
using System.Linq;
using System;
/*
In Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-2 Wed Feb 26 23:23:50 UTC 2020),
following expressions have difference results.
why?
*/
static class Program {
static void Main() {
@ritalin
ritalin / BeSame.ps1
Last active January 30, 2019 08:22
Pester operator for object properties matching.
Import-Module Pester -MinimumVersion 4.0.5 -Force -Scope Local
Import-Module (Get-Module Pester | % NestedModules | ? Name -eq "Format" | % Path) -Scope Local
function BeSame([object[]]$ActualValue, [object[]]$ExpectedValue, [switch]$Negate, [string[]]$Property = $null, [switch]$Loose) {
_AssertSameObject $ActualValue $ExpectedValue $Property $Negate $Loose $false
}
function BeSameExactly([object[]]$ActualValue, [object[]]$ExpectedValue, [switch]$Negate, [string[]]$Property = $null, [switch]$Loose) {
_AssertSameObject $ActualValue $ExpectedValue $Property $Negate $Loose $true
}
@ritalin
ritalin / SortOrderAssertOperation.ps1
Last active January 7, 2019 07:54
Operator to test sort order for Pester.
Import-Module Pester -MinimumVersion 4.0.5 -Force
<#
.EXAMPLE
It "Hoge" {
$collection | Should -BeSorted Field1,...
}
#>
function BeSorted($ActualValue, [string[]]$SortFields, [switch]$Negate, [int]$Sample = -1) {
$values =
@ritalin
ritalin / StartPester.ps1
Last active December 11, 2018 09:01
クリーンな環境でPesterによるテスト実行 (Original: Ensuring a Clean PowerShell Session for Your Pester Tests / https://mcpmag.com/articles/2018/02/01/clean-powershell-session-for-pester.aspx )
function InvokePowerShellCommand
{
[CmdletBinding()]
param
(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$Command
)
@ritalin
ritalin / InterfaceTestDriver.dpr
Created August 17, 2018 02:45
インターフェースの委譲のオーバーライドのテスト
program InterfaceTestDriver;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
IMyIntf = interface
['{D9075E8D-417D-4358-ABA0-6688B245EF6A}']