Skip to content

Instantly share code, notes, and snippets.

View yhirano's full-sized avatar

Yuichi Hirano yhirano

View GitHub Profile
@yhirano
yhirano / fetch_4u.rb
Created March 28, 2012 10:54
Download a beauty picture from http://4u-beautyimg.com/
#!/usr/bin/env ruby
# Download a beauty picture from http://4u-beautyimg.com/
#
# Usage:
# $ fetch_4u.rb # Download a picture to /tmp/4u.jpg
# $ fetch_4u.rb ~/pic.jpg # Download a picture to ~/pic.jpg
require 'open-uri'
require "rexml/document"
@yhirano
yhirano / fetch_google_image.py
Last active February 24, 2021 22:48
[No longer available] Download a random picture from Google image search.
#!/usr/bin/env python
# coding: utf-8
# Download a random picture from Google image search.
#
# Usage:
# $ fetch_google_image.py cat cute # Download a cute cat picture
import os
import sys
@yhirano
yhirano / esp32_ap_sample.c
Created April 20, 2017 22:07
ESP32 Wifi AP mode sample
#include <esp_event.h>
#include <esp_event_loop.h>
#include <esp_log.h>
#include <esp_system.h>
#include <esp_wifi.h>
#include <freertos/FreeRTOS.h>
#include <nvs_flash.h>
// Defines for WiFi
#define SSID "YOUR SSID"
@yhirano
yhirano / NumberLoopBenchmark.swift
Last active June 21, 2017 23:53
数値をループさせるアルゴリズムの速度比較
func runBench() {
let loop = 1000000
let measurements = 100
var total = 0.0
// If condition loop
for _ in 0..<measurements {
let timeElapsed = timeElapsedInSecondsWhenRunningCode {
var num: Int = 0
@yhirano
yhirano / RxDownloader.java
Last active June 15, 2018 03:27
Downloader with RX for Android
// Copyright (c) 2017 Yuichi Hirano
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
@yhirano
yhirano / mvi.sh
Last active October 23, 2017 22:26
The script to move Android images of exported from Adobe Illustrator CC(21) to directories for each resolution
#!bin/sh
dirs=("xxxhdpi" "xxhdpi" "xhdpi" "hdpi" "mdpi")
for dir in "${dirs[@]}"; do
mkdir drawable-${dir}
for file in *${dir}.png; do
mv -- "$file" "drawable-${dir}/${file%%${dir}.png}.png"
done
done
@yhirano
yhirano / colorblend.rb
Created October 8, 2017 03:49
HTMLカラーコードで指定した色をRGBに分解して、それぞれに指定の割合をかけてHTMLカラーコードに戻すスクリプト
#!/usr/bin/env ruby
# Color blend
#
# Usage
# $ colorblend.rb cfd2ce 0.9
# babdb9
require 'color'
require 'pp'
@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])
@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 / 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();
}