Skip to content

Instantly share code, notes, and snippets.

View SelvinPL's full-sized avatar

SelvinPL SelvinPL

View GitHub Profile
class PropExtension extends Closure {
final map = [:]
PropExtension() {
super(null)
}
def methodMissing(String name, args) {
map[name] = args[0]
}
}
@SelvinPL
SelvinPL / fadeinout.c
Last active February 28, 2024 21:30
Fade out and in for GG and SMS (GBDK2020)
#if defined(MASTERSYSTEM)
#define COL_DEPTH_BITS 2
#else
#define COL_DEPTH_BITS 4
#endif
#define COL_PER_PALETTE 16
#define R_MASK ((1<<COL_DEPTH_BITS)-1)
#define G_MASK (R_MASK << COL_DEPTH_BITS)
@SelvinPL
SelvinPL / _only.cs
Last active July 19, 2023 15:06
SO76722226
void Main()
{
GetItems(MathOperation.Average).Dump();
GetItems(MathOperation.Max).Dump();
GetItems(MathOperation.Min).Dump();
}
IEnumerable<Item> GetItems(MathOperation mathOperation)
{
Expression<Func<IGrouping<long, Album>, decimal>> operation = mathOperation switch
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22621
12th Gen Intel Core i7-12700H, 1 CPU, 20 logical and 14 physical cores
[Host] : .NET Framework 4.8 (4.8.9167.0), X86 LegacyJIT
DefaultJob : .NET Framework 4.8 (4.8.9167.0), X86 LegacyJIT
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
|
----------------------------------- |-----------:|----------:|----------:|-------:|----------:|
| CantonWithValueTuple | 777.0 ns | 5.18 ns | 4.84 ns | - | - |
| CantonAccelerationsClass | 551.9 ns | 10.18 ns | 9.52 ns | 0.3815 | 2,003 B |
@SelvinPL
SelvinPL / net48.txt
Last active July 4, 2023 11:48
SO76611515
void Main()
{
var summary = BenchmarkRunner.Run<Test>();
}
public class Test
{
[Benchmark]
public void Max()
{
static class Ext
{
public static TAccumulate AggregateUntil<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, (bool, TAccumulate)> func)
{
foreach(var item in source)
{
var res = func(seed, item);
seed = res.Item2;
if(res.Item1)
break;
@SelvinPL
SelvinPL / example.c
Last active March 10, 2024 04:45
modified LUFA hid parser for simple use with tinyusb - gamepad example
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 Selvin
*
*/
#include "ch32v20x.h" //include your board
#include "tusb.h"
#include <stdbool.h>
@SelvinPL
SelvinPL / ch32v20x_usb.h
Created April 14, 2023 14:29
tinyusb proof of concept IRQ host implementation for CH20X (prolly can be ported to 58x)
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_usb.h
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : CH32V20x Device Peripheral Access Layer System Header File.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
@SelvinPL
SelvinPL / hcd.c
Created March 28, 2023 07:43
TinyUSB host implementation for CH58X (dirty not using IRQ)
#include "ch58x_common.h"
#include "common/tusb_common.h"
#include "common/tusb_types.h"
#include "common/tusb_debug.h"
#include "hcd.h"
#include <assert.h>
#define ch58x_info(...) TU_LOG(2, __VA_ARGS__)
#define ch58x_trace(...) TU_LOG(3, __VA_ARGS__)
@SelvinPL
SelvinPL / Maven.csproj
Last active March 28, 2023 14:42
Download maven and unpack and print all txt files in downloaded artifacts
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="DisplayMessages">
<ItemGroup>
<MavenArtifact Include="commons-compress-1.23.0" Group="org.apache.commons" Artifact="commons-compress" Version="1.23.0" />
<MavenArtifact Include="commons-compress-1.22" Group="org.apache.commons" Artifact="commons-compress" Version="1.22" />
</ItemGroup>
<Target Name="DownloadArtifacts" BeforeTargets="UnzipArchive">
<DownloadFile
SourceUrl="https://repo1.maven.org/maven2/$([MSBuild]::ValueOrDefault('%(MavenArtifact.Group)', '').Replace('.', '/'))/$([MSBuild]::ValueOrDefault('%(MavenArtifact.Artifact)', '').Replace('.', '/'))/%(MavenArtifact.Version)/%(MavenArtifact.Artifact)-%(MavenArtifact.Version).jar"