Skip to content

Instantly share code, notes, and snippets.

View petitviolet's full-sized avatar
🕶️
😃

petitviolet petitviolet

🕶️
😃
View GitHub Profile
# 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 / nginx_deployment.yaml
Created March 11, 2018 11:04
sample Nginx configuration on Kubernetes using ConfigMap to configure nginx.
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
user nginx;
worker_processes 3;
error_log /var/log/nginx/error.log;
events {
@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 / MainThreadCallback.java
Last active May 13, 2023 12:15
OkHttp Callback on Main Thread.
public abstract class MainThreadCallback implements Callback {
private static final String TAG = MainThreadCallback.class.getSimpleName();
abstract public void onFail(final Exception error);
abstract public void onSuccess(final String responseBody);
@Override
public void onFailure(final Request request, final IOException e) {
@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 / 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 / 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) {
@petitviolet
petitviolet / AkkaStreamPracWithActor.scala
Last active April 11, 2021 21:07
Akka-Stream with Actor using ActorPublisher and ActorSubscriber
package net.petitviolet.ex.persistence.task
import akka.NotUsed
import akka.actor._
import akka.pattern.ask
import akka.stream.actor.ActorSubscriberMessage.{ OnComplete, OnNext }
import akka.stream.actor.{ ActorPublisher, ActorSubscriber, OneByOneRequestStrategy, RequestStrategy }
import akka.stream.{ ActorMaterializer, ClosedShape }
import akka.util.Timeout
import org.reactivestreams.Publisher
@petitviolet
petitviolet / thread_local_random.md
Last active February 11, 2021 15:51
[Scala]ThreadLocalRandom is fast.

ThreadLocalRandom is faster than Random

val n = 100
Random.nextInt(n)
ThreadLocalRandom.current().nextInt(n)

why ThreadLocalRandom is faster