Skip to content

Instantly share code, notes, and snippets.

@tera-ny
tera-ny / Preload.tsx
Last active November 13, 2022 16:13
Component to preload images
import { FC, PropsWithChildren, ReactNode, useEffect, useState } from "react";
interface Props {
srcSets: { [key: string]: string };
fallback?: ReactNode;
}
const Preload: FC<PropsWithChildren<Props>> = ({
children,
fallback,
@tera-ny
tera-ny / vscode.code-snippets
Created November 11, 2022 08:03
Snippets of function component
{
"Define FunctionComponents": {
"scope": "typescript,typescriptreact",
"prefix": "fc",
"body": [
"import { FC } from \"react\";",
"",
"const $TM_FILENAME_BASE: FC = () => <></>;",
"",
"export default $TM_FILENAME_BASE",
@tera-ny
tera-ny / main.cjs
Created November 1, 2022 16:03
Storybook configuration file using vite
const { loadConfigFromFile, mergeConfig } = require("vite");
const path = require("path");
module.exports = {
...
async viteFinal(config) {
const result = await loadConfigFromFile(
{ command: "build", mode: "development" },
path.resolve(__dirname, "path to vite config")
);
@tera-ny
tera-ny / assertSnapshot.ts
Created April 13, 2022 05:13
Assertion function to perform SnapshotTest in Deno with update option
import {
assertEquals,
equal,
} from "https://deno.land/std@0.132.0/testing/asserts.ts";
import { copy } from "https://deno.land/std@0.132.0/fs/mod.ts";
export const assertSnapshot = async (
receivedPath: string,
expectedPath: string
) => {
@tera-ny
tera-ny / config.ts
Created October 23, 2021 08:31
google cloud transcoder api job config.
const request = {
parent: client.locationPath(projectID, regionID),
job: {
inputUri,
outputUri,
config: {
pubsubDestination: {
topic: pubsubTopicID,
},
elementaryStreams: [
@tera-ny
tera-ny / simulate.py
Created October 13, 2021 14:15
ネットワーク品質をシミュレートするシミュレータです。
def simulate(csv, c):
d_prev = 0
result_t = []
result_a = []
for row in csv:
a_i = float(row[0])
l_i = float(row[1])
s_i = l_i*8/c
d_i = max(d_prev, a_i) + s_i
t_i = d_i - a_i
#include <stdio.h>
char* my_strcpy(char* to, const char* from) {
size_t i;
for (i = 0; from[i] != '\0'; i++) {
to[i] = from[i];
}
to[i] = '\0';
return to;
}
#include <stdio.h>
int my_strlen(char* s) {
int count = 0;
while (s[count] != '\0')
{
count++;
}
return count;
}
@tera-ny
tera-ny / Ex+View.swift
Created May 9, 2021 13:47
Controlling which methods are enabled by starting with the bool flag in SwiftUI Component
//
// Ex+View.swift
// OrangeJuice
//
// Created by tera_ny on 2021/05/09.
//
import SwiftUI
extension View {
@tera-ny
tera-ny / Readme.md
Last active November 21, 2020 15:04
Propose a product cell layout that supports aspect-fill images with SwiftUI components