Skip to content

Instantly share code, notes, and snippets.

@Atsumi3
Atsumi3 / CharSequenceClickExtension.kt
Created Nov 12, 2019
文字列をタップした時の制御を楽にする拡張
View CharSequenceClickExtension.kt
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ClickableSpan
import android.view.View
import java.util.regex.Pattern
// 格納先のTextViewに以下の設定が必須
// textView.movementMethod = LinkMovementMethod.getInstance()
fun CharSequence.setTextClickListener(regex: String = "", onClick: ((text: String) -> Unit)): SpannableString {
// regexが空だったら自分自身を指定する (テキスト全てがClickableになる)
@Atsumi3
Atsumi3 / methodMonitoring.swift
Created Mar 18, 2019
[Swift4] メソッドの動作確認用クロージャ
View methodMonitoring.swift
/*
// example:
func getAuthToken() -> String {
return methodMonitoring {
return apiService.requestToken()
}
}
MONITORING: ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MONITORING: ┃ Thread: <NSThread: 0x6000036ef280>{number = 1, name = main}
View IdlingResourceExtension.kt
import android.support.test.espresso.IdlingRegistry
import android.support.test.espresso.IdlingResource
inline fun <T: IdlingResource?, R> T.use(block: (T) -> R): R {
var exception: Throwable? = null
try {
IdlingRegistry.getInstance().register(this)
return block(this)
} catch (e: Throwable) {
exception = e
@Atsumi3
Atsumi3 / ViewListAdapter.kt
Last active Dec 13, 2018
カスタムビューの表示や動作チェックに使えるかも
View ViewListAdapter.kt
// usage
val adapter = ViewListAdapter(listOf(TextView::class, ImageView::class, Button::class)).apply {
listener = object : ViewListAdapter.Listener {
override fun onViewSelect(selectedViewInstance: View?) {
when(selectedViewInstance) {
is TextView -> selectedViewInstance.text = "textView"
is ImageView -> selectedViewInstance.setImageResource(android.R.drawable.ic_input_add)
is Button -> selectedViewInstance.text = "button"
}
}
@Atsumi3
Atsumi3 / KClassExtensions.kt
Created Dec 13, 2018
Create instance from KClass<out View>, with constructor parameters.
View KClassExtensions.kt
fun KClass<out View>.get(context: Context): View? = primaryConstructor?.call(context)
@Atsumi3
Atsumi3 / VagrantFile
Created Aug 23, 2018
[VagrantFile] CentOS7 + docker-compose
View VagrantFile
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provision "shell", inline: <<-SHELL
# update
sudo yum update
# add docker repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
@Atsumi3
Atsumi3 / Main.java
Created Jun 14, 2018
Simple Dagger2 (Pure Java)
View Main.java
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import javax.inject.Inject;
public class Main {
public static void main(String[] args) {
AnimalCry animalCry = new AnimalCry();
animalCry.cry();
@Atsumi3
Atsumi3 / memo1
Last active Oct 11, 2016
NS*CalendarUnit -> NSCalendarUnit*
View memo1
# pattern
## 3: NSDayCalendarUnit
## 17: NSYearForWeekOfYearCalendarUnit
NS(.{3,17})CalendarUnit
# replace
NSCalendarUnit$1
View Factory-CSharp.cs
// Factory Method
public interface Human {
String getName();
}
/// Tanaka Factory
sealed class TanakaImpl : Human {
public string getName() {
return "Tanaka";
}
View Factory-Java.java
// Factory Method
public interface Human {
String getName();
}
/// Tanaka Factory
final class TanakaImpl implements Human {
@Override public String getName() {
return "Tanaka";
}