Skip to content

Instantly share code, notes, and snippets.

View nodahikaru's full-sized avatar
:octocat:
Thinking, Coding, Studying

Noda Hikaru nodahikaru

:octocat:
Thinking, Coding, Studying
View GitHub Profile
@nodahikaru
nodahikaru / foo_test.dart
Created June 24, 2022 17:11 — forked from Esgrima/foo_test.dart
16 Tips for Widget Testing in Flutter
// https://gist.github.com/Esgrima/c0d4bff4b0d3909daf8994410cd659ce
// https://dartpad.dev/c0d4bff4b0d3909daf8994410cd659ce
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:boolean_selector/boolean_selector.dart';
// (TODO: Tip # 1) Consider making frequently used variables/values constants
const _fooConst1 = '';
const _fooConst2 = '';
import { useLocation } from "react-router-dom";
export function useQueryParams() {
const query = new URLSearchParams(useLocation().search);
return query;
}
//
// RemoteImage.swift
// List
//
// Created by noda on 12/13/20.
//
import SwiftUI
struct RemoteImage: View {
@nodahikaru
nodahikaru / captureAndShareImage.dart
Created August 14, 2020 17:01
Capture and share images from RepaintBoundary
Future<void> _captureAndSharePng() async {
try {
RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
var image = await boundary.toImage();
ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
final tempDir = await getTemporaryDirectory();
final file = await new File('${tempDir.path}/image.png').create();
await file.writeAsBytes(pngBytes);
@nodahikaru
nodahikaru / ScreenConsumer.js
Created June 4, 2020 07:46
ScreenConsumer for global usable using Context API
import React from "react";
import PropTypes from "prop-types";
import DimensionConsumer from "./DimensionContext";
import { getScreenWidth, getScreenHeight } from "./selectors";
const ScreenConsumer = ({ children }) => {
return (
<DimensionConsumer>
{dimensions =>
children(getScreenWidth(dimensions), getScreenHeight(dimensions))
@nodahikaru
nodahikaru / ScreenConsumer.js
Created June 4, 2020 07:46
ScreenConsumer for global usable using Context API
import React from "react";
import PropTypes from "prop-types";
import DimensionConsumer from "./DimensionContext";
import { getScreenWidth, getScreenHeight } from "./selectors";
const ScreenConsumer = ({ children }) => {
return (
<DimensionConsumer>
{dimensions =>
children(getScreenWidth(dimensions), getScreenHeight(dimensions))
import React, { useContext } from 'react'
import { ArrowUp, Download, Star, Trash, X, Edit2 } from 'react-feather'
import { useDispatch, useSelector } from 'react-redux'
import { LabelText } from '@resources/LabelText'
import { TestID } from '@resources/TestID'
import { ContextMenuOption } from '@/components/NoteList/ContextMenuOption'
import { downloadNotes } from '@/utils/helpers'
import {
@nodahikaru
nodahikaru / NotEditor.tsx
Last active June 4, 2020 07:41
Redux hooks
import dayjs from 'dayjs'
import React from 'react'
import { Controlled as CodeMirror } from 'react-codemirror2'
import { useDispatch, useSelector } from 'react-redux'
import { getActiveNote } from '@/utils/helpers'
import { updateNote } from '@/slices/note'
import { togglePreviewMarkdown } from '@/slices/settings'
import { NoteItem } from '@/types'
import { EmptyEditor } from '@/components/Editor/EmptyEditor'
@nodahikaru
nodahikaru / custom_scaffold.dart
Created April 23, 2020 16:43
Fancy Scaffold using Slivers
class CustomScaffold extends StatelessWidget {
const CustomScaffold._({
Key key,
this.title,
this.color,
this.sliverChildDelegate,
this.padding = const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
this.actions,
this.onRefresh,
}) : super(key: key);
@nodahikaru
nodahikaru / fileupload.dart
Last active April 8, 2020 14:35
File uploading in Flutter/Dart
import 'dart:async';
import 'dart:convert';
import 'dart:core';
import 'dart:io';
import 'package:http/http.dart' as http;
typedef OnUploadProgressCallback = void Function(int sentBytes, int totalBytes);
Future<String> fileUpload({@required File file, OnUploadProgressCallback onUploadProgress}) async {
assert(file != null);