Skip to content

Instantly share code, notes, and snippets.

View kamikat's full-sized avatar

Kamikat kamikat

View GitHub Profile
@kamikat
kamikat / moveit_compute_fk.py
Created September 15, 2024 16:29
Forward kinematics with `/compute_fk` interface.
import typing
import rospy
import moveit_commander
import moveit_msgs.srv
def moveit_compute_fk(
move_group: moveit_commander.MoveGroupCommander,
joint_position: typing.List[float],
ee_link = "tool0"
):
@kamikat
kamikat / routing-hooks.ts
Last active August 4, 2023 02:14
Drop-in replacement of `useLocation()`/`useNavigate()` hooks in browser.
import { useCallback, useLayoutEffect, useMemo, useReducer } from "react";
function createHooks() {
const listeners: (() => void)[] = [];
window.addEventListener("popstate", () => {
for (const listener of listeners) {
listener();
}
});
@kamikat
kamikat / async-input-helper.ts
Last active December 27, 2022 03:50
Workaround composition event problem in controlled React input components.
import { useEffect, useState, useRef } from "react";
export function useAsyncInputRef<T extends HTMLElement & { value: string }>(
value: string,
forwardRef?: React.RefObject<T>
) {
const [compositionFlag, setComposition] = useState(false);
const newRef = useRef<T>(null);
const ref = forwardRef || newRef;
@kamikat
kamikat / react-component-package.patch
Last active October 11, 2019 04:16
Convert CRA project to re-distributable component package.
diff --git a/.gitignore b/.gitignore
index 4d29575..3835823 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
+
+/dist
@kamikat
kamikat / logger.js
Created November 13, 2018 09:02
Colorized logger of [email protected] (boilerplate)
const process = require('process');
const winston = require('winston');
const clc = require('cli-color');
const {
TERM = '',
LOG_LEVEL = 'info'
} = process.env;
const colors = ~TERM.indexOf('256') ? {
@kamikat
kamikat / date.js
Created November 13, 2018 08:51
Native JavaScript date manipulation, inspired by https://github.com/you-dont-need/You-Dont-Need-Momentjs.
const startOf = {
d: (d) => {
d.setHours(0, 0, 0, 0);
return d;
},
w: (d) => {
d.setDate(d.getDate() - (d.getDay() || 7) + 1);
d.setHours(0, 0, 0, 0);
return d;
},
@kamikat
kamikat / volume-command.sh
Created October 19, 2018 07:14
Backup & restore a local volume from docker.
#!/bin/sh
BUSYBOX_IMAGE=${BUSYBOX_IMAGE:-busybox}
BUSYBOX_IMAGE_ID=$(docker images -q $BUSYBOX_IMAGE | head -n1)
check_busybox() {
if [ -z "$BUSYBOX_IMAGE_ID" ]; then
echo >&2 "error: $BUSYBOX_IMAGE image not found."
exit 1
fi
@kamikat
kamikat / exiftool-android.md
Last active September 26, 2022 07:08
Setup exiftool command for Terminal Emulator on Android (ROOT required).
@kamikat
kamikat / eri.xml
Last active June 2, 2018 17:24
ERI file to set LTE network name (fix "Roaming Indicator OFF" problem with LineageOS capricorn).
<?xml version="1.0" encoding="UTF-8"?>
<EriFile VersionNumber="1357" NumberOfEriEntries="14" EriFileType="1">
<CallPromptId Id="0" CallPromptText="CallPromptId0" />
<CallPromptId Id="1" CallPromptText="CallPromptId1" />
<CallPromptId Id="2" CallPromptText="CallPromptId2" />
<EriInfo RoamingIndicator="0" IconIndex="1" IconMode="0" EriText="CT-LTE Roam" CallPromptId="0" AlertId="0" />
<EriInfo RoamingIndicator="1" IconIndex="1" IconMode="0" EriText="CT-LTE" CallPromptId="0" AlertId="0" />
<EriInfo RoamingIndicator="2" IconIndex="1" IconMode="0" EriText="CT-LTE Roam" CallPromptId="0" AlertId="0" />
<EriInfo RoamingIndicator="65" IconIndex="65" IconMode="0" EriText="T-CDMA 65" CallPromptId="0" AlertId="0" />
<EriInfo RoamingIndicator="66" IconIndex="1" IconMode="0" EriText="T-CDMA Ext 66" CallPromptId="0" AlertId="0" />
@kamikat
kamikat / logger.js
Created May 23, 2018 04:37
256color compatible logger configuration for winston.
var clc = require('cli-color');
var { Logger, transports } = require('winston');
var { formatter, timestamp } = require('winston-console-formatter')({
colors: ((term) => (~term.indexOf('256')) ? {
silly: clc.xterm(33),
debug: clc.xterm(207),
info: clc.xterm(48),
warn: clc.xterm(226),
error: clc.xterm(196),