Skip to content

Instantly share code, notes, and snippets.

View kamikat's full-sized avatar

Kamikat kamikat

View GitHub Profile
@kamikat
kamikat / image64.sh
Last active January 31, 2024 06:08 — forked from puppybits/image64.sh
Create data URI image from Terminal command
#!/bin/sh
# Examples:
# ./image64.sh myImage.png
# outputs: data:image/png;base64,xxxxx
# ./image64.sh myImage.png -img
# outputs: <img src="data:image/png;base64,xxxxx">
append=""
if [[ "$1" == *.gif ]]; then
@kamikat
kamikat / trig.scss
Last active December 7, 2023 12:50
SCSS/SASS module calculating sin/cos/tan using Taylor Expansion.
///////////////////////////////////////////////////////////
// Plain SASS Trigonometry Algorithm in Taylor Expansion //
// //
// Based on //
// http://japborst.net/posts/sass-sines-and-cosines //
///////////////////////////////////////////////////////////
$pi: 3.14159265359;
$_precision: 10;
@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 / get-application-icon.sh
Created February 14, 2017 08:52
Extracting application icon from APK file.
#!/bin/sh
GENERATOR="/^application-icon-(\\d+):(.*)/ && print \"unzip -o $1 \$2 && mv \$2 $(basename $1 .apk)-\$1.png\n\""
aapt d --values badging $1 | perl -n -e"$GENERATOR" | sh
rm -rf res/
@kamikat
kamikat / cookie-chrome.sh
Last active March 25, 2023 18:38
export curl cookie text from firefox and chrome on linux
@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 / exiftool-android.md
Last active September 26, 2022 07:08
Setup exiftool command for Terminal Emulator on Android (ROOT required).
@kamikat
kamikat / ProgressCircle.java
Created July 28, 2014 06:18
Implement circle progress indicator view on android.
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
public class ProgressCircle extends View {
@kamikat
kamikat / layout.xml
Last active September 1, 2021 17:40
NestedScrollView + SwipeRefreshLayout + RecyclerView
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
@kamikat
kamikat / geohash.sql
Last active April 30, 2021 16:50
MySQL Queries on GeoHash with arbitrary Base32 encoding table.
--
-- Query unique GeoHash prefixes
--
SELECT
SUBSTR(p.last_location, 1, :length) prefix,
COUNT(p.id) count
FROM
user_profile p
GROUP BY prefix;