Skip to content

Instantly share code, notes, and snippets.

package golangglobalcachewithmutex
import "sync"
type MemCache[K comparable, T any] struct {
cache map[K]T
mutex *sync.Mutex
}
func (m MemCache[K, T]) Get(key K) (T, bool) {
use std::collections::HashMap;
fn parse_string(chars: &[char]) -> (String, &[char]) {
if chars[0] != '"' {
unreachable!()
}
let mut result = vec![];
let mut index = 1;
import React, { useState, useCallback, MouseEvent } from "react";
import { css } from "@emotion/core";
const RippleEffect = ({
top,
left,
radius,
opacity,
transition,
scale,
/** @jsx jsx */
import React from "react";
import { jsx, css } from "@emotion/core";
export const GamingTextField: React.FC = () => {
return (
<div
css={css`
background: linear-gradient(
217deg,
@myuon
myuon / DP.ts
Last active January 31, 2020 14:04
type D<T> = {
[P in keyof T]?: T[P] extends Array<infer U> ? Array<D<U>> : T[P]
}
type W<V> = {
wrapper: V
}
type A = D<{
hoge: number,
@myuon
myuon / quartz.qz
Last active November 21, 2019 15:58
func identity<A>(x: A): A {
x
}
enum List<A> {
Nil,
Cons(A, List<A>),
}
record User {
@myuon
myuon / sanitize.sh
Created September 17, 2019 08:38
csv-sanitize
# https://www.quora.com/What-is-a-sed-script-that-will-remove-the-n-character-but-only-if-it-is-inside-characters-delimited-string-not-the-n-that-is-actually-at-the-end-of-the-virtual-line
$ mlr --csv --rs lf --implicit-csv-header --headerless-csv-output --quote-all put '
for (col_no in $*) {
$[col_no]=gsub($[col_no], "\n", " \\\\n ")
}
' my.csv > sanitized.csv
{-# LANGUAGE BangPatterns #-}
import Gauge.Main
import Control.Monad
import Control.Monad.State.Strict
import qualified Data.Vector.Unboxed.Mutable as V
import Data.ByteString.Internal (accursedUnutterablePerformIO)
{-
benchmarked accursed
time 5.238 μs (5.168 μs .. 5.339 μs)
{-# LANGUAGE BangPatterns #-}
import Gauge.Main
import Control.Monad
import Control.Monad.State.Strict
import qualified Data.Vector.Unboxed.Mutable as V
import Data.ByteString.Internal (accursedUnutterablePerformIO)
{-
benchmarked accursed
time 136.3 μs (135.7 μs .. 137.0 μs)
import Gauge.Main
import Control.Monad
import Control.Monad.State.Strict
import Data.IORef
import qualified Data.Vector.Unboxed.Mutable as V
import Data.Primitive.MutVar
{-
benchmarked IORef
time 3.196 μs (3.170 μs .. 3.226 μs)