Skip to content

Instantly share code, notes, and snippets.

View yhirano's full-sized avatar

Yuichi Hirano yhirano

View GitHub Profile
@yhirano
yhirano / ThinkPad T14 Gen1 (AMD)にUbuntu 21.04をインストールした際のメモ.md
Last active September 13, 2021 04:50
ThinkPad T14 Gen1 (AMD)にUbuntu 21.04をインストールした際のメモ
import android.os.SystemClock
import androidx.collection.LruCache
import java.util.*
/**
* @param expireTime Cache expire time(ms).
*/
class ExpiringLruCache<K: Any, V: Any>(maxSize: Int, private val expireTime: Long) {
private val cache: LruCache<K, V> = CustomLruCache(maxSize)
private val expirationTimes: MutableMap<K, Long> = HashMap<K, Long>(maxSize)
import android.os.SystemClock
/**
* @param expireTime Cache expire time(ms).
*/
class ExpiringCache<V: Any>(private val expireTime: Long) {
private var cache: V? = null
private var expirationTime: Long = 0
fun get(): V? {
@yhirano
yhirano / ThinkPad T14 Gen1 (AMD)にUbuntu 20.10をインストールした際のメモ.md
Last active February 8, 2021 15:55
ThinkPad T14 Gen1 (AMD)にUbuntu 20.10をインストールした際のメモ
@yhirano
yhirano / csv_plot_with_lowpassfilter.py
Created July 14, 2020 15:08
CSV plot with lowpassfilter.
import pandas as pd
import matplotlib.pyplot as plt
def lowpass(values, strength):
result = []
f = 0
for v in values:
if not result:
result.append(v)
f = v
import UIKit
extension UIImage {
func fixedOrientation() -> UIImage? {
guard imageOrientation != UIImage.Orientation.up else {
return self
}
guard let cgImage = self.cgImage else {
return nil
@yhirano
yhirano / GradleSampleCode.java
Last active November 4, 2017 11:33
Show original image size on Glide4.
GlideApp.with(imageView.getContext())
.load(url)
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
if (resource instanceof BitmapDrawable) {
int width = ((BitmapDrawable) resource).getBitmap().getWidth();
int height = ((BitmapDrawable) resource).getBitmap().getHeight();
ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
layoutParams.width = width;
@yhirano
yhirano / ExifRotationBitmap.java
Created October 20, 2017 10:21
Android Exif rotation.
private Bitmap getBitmap(@NonNull File file) {
int exifRotation = getExifRotation(file);
if (exifRotation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(exifRotation);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
if (!bitmap.isRecycled()) {
bitmap.recycle();
}
@yhirano
yhirano / DataBindingHelper.java
Last active December 20, 2018 10:05
My DataBindingHelper for Android.
package your.project.view.helper;
import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
@yhirano
yhirano / convert9patch.rb
Created October 8, 2017 03:50
指定したPNG画像の外周に透明の1ピクセルを追加するスクリプト。Androidの9patch用。
#!/usr/bin/env ruby
require 'pathname'
require 'rmagick'
if ARGV.empty?
puts 'Usage: convert9patch.rb [png]'
exit
end
if !File.exist?(ARGV[0])