Skip to content

Instantly share code, notes, and snippets.

View petitviolet's full-sized avatar
🕶️
😃

petitviolet petitviolet

🕶️
😃
View GitHub Profile
@petitviolet
petitviolet / SeedRandom.cs
Created July 17, 2023 07:59
SeedRandom to deal with seed value of UnityEngine.Random
using System;
public class SeedRandom
{
private UnityEngine.Random.State _randomState;
public static int DefaultSeed()
{
return (int)System.DateTime.Now.Ticks;
}
@petitviolet
petitviolet / Result.cs
Created September 7, 2022 12:04
Result type to hold a result of either success or failure in Unity C#
using System;
namespace MyNamespace
{
/// holds an either succeeded or failed result
// need latest C# version to use <out T, out E> instead
public interface Result<T, E> where E : Exception
{
public bool OK { get; }
@petitviolet
petitviolet / JsonHttp.cs
Created September 7, 2022 12:02
Json over HTTP in Unity C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
@petitviolet
petitviolet / rspec_any_instance_count.rb
Created August 16, 2021 12:47
allow_any_instance_of to count up the number of method calls across different instances
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem 'rspec', '~> 3.0'
end
@petitviolet
petitviolet / main.js
Created May 26, 2021 14:50
Subscribe a web page by GoogleAppScript
const URL = 'https://example.com';
const CELL = 'A1'
const MAIL_TO = 'mail@example.com';
// Create a trigger to run `main` periodically
function main() {
const sheet = SpreadsheetApp.getActiveSheet();
const lastDate = readLastDate(sheet);
const today = Utilities.formatDate(new Date(), 'UTC', 'yyyy-MM-dd');
if (lastDate === null || lastDate == today) {
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", "6.0.0"
@petitviolet
petitviolet / Cargo.toml
Last active September 6, 2020 14:26
Simple logger implementation in Rust
[dependencies]
log = { version = "0.4", features = [ "std" ] }
@petitviolet
petitviolet / main.dig
Created April 30, 2020 05:37
digdag's `http_call>` operator sample
+run_workflow:
http_call>: http://$(ip):8000/http_call_dig
retry: false
_retry: 2
@petitviolet
petitviolet / route.go
Created April 29, 2020 11:39
oEmbed API for blog.petitviolet.net
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
@petitviolet
petitviolet / rstruct.rb
Last active January 12, 2020 14:57
Struct implemented with Ruby
module Rstruct
def self.new(*attributes)
names = caller.map do |stack|
# ".../hoge.rb:7:in `<module:Hoge>'"
if (m = stack.match(/\A.+in `<(module|class):(.+)>.+/))
m[2]
end
end.reject(&:nil?)
file_name, line_num = caller[0].split(':')
line_executed = File.readlines(file_name)[line_num.to_i - 1]