Skip to content

Instantly share code, notes, and snippets.

View VibeMage's full-sized avatar
🏠
Working from home

VibeMage VibeMage

🏠
Working from home
View GitHub Profile
@VibeMage
VibeMage / eco-server-order-on-ovhcloud-api.md
Created November 8, 2024 23:44 — forked from adns44/eco-server-order-on-ovhcloud-api.md
Eco server order process with OVHcloud API step-by-step

OVH - How to use the API to order any server? The answer is here!

I ASK YOU IN FIRST

This process is automateable. I'll write the know-how, how to do it. I kindly ask you! Do NOT ABUSE it! Please keep the oportunity to order limited edition servers for other ones!

How the OVH API works?

First of all, OVH provides API libraries to access the API. And for this too, they have an API console where you can try it. For now, we'll see the API console. We'll place an older. Lets go!

@VibeMage
VibeMage / once.kt
Last active March 1, 2023 16:31
the method executed only once
import kotlinx.coroutines.*
val myData by lazy(LazyThreadSafetyMode.NONE) {
loadDataFromNetwork()
}
suspend fun loadDataFromNetwork(): MyData {
// 模拟网络请求
delay(1000)
return MyData(/* ... */)
@VibeMage
VibeMage / CountDownCoroutines.kt
Created June 16, 2022 14:56
CountDown Coroutines
fun countDownCoroutines(
total: Int,
scope: CoroutineScope,
onTick: (Int) -> Unit,
onStart: (() -> Unit)? = null,
onFinish: (() -> Unit)? = null,
): Job {
return flow {
for (i in total downTo 0) {
emit(i)
@VibeMage
VibeMage / CallToObservable.java
Created March 3, 2020 07:23
[Retrofit Call to Observable]#Android
public static <T extends ApiResponse> Observable<T> CallToObservable(Call<T> originalCall) {
return Observable.<T>create(subscriber -> {
Call<T> call = originalCall.clone();
CallArbiter<T> arbiter = new CallArbiter<>(call, subscriber);
subscriber.add(arbiter);
subscriber.setProducer(arbiter);
Response<T> response;
try {
response = call.execute();
if (!response.isSuccessful()) {
@VibeMage
VibeMage / DisableableAppBarLayoutBehavior.java
Created March 3, 2020 03:27
[disable/re-enable the expansion CoordinatorLayout behavior]#Android
public class DisableableAppBarLayoutBehavior extends AppBarLayout.Behavior {
private boolean mEnabled;
public DisableableAppBarLayoutBehavior() {
super();
}
public DisableableAppBarLayoutBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@VibeMage
VibeMage / expand-collapse.java
Created February 14, 2020 09:04 — forked from ZkHaider/expand-collapse.java
Simple Expand / Collapse RecyclerView Item
public static class ExampleViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
private int originalHeight = 0;
private boolean isViewExpanded = false;
private YourCustomView yourCustomView
public ExampleViewHolder(View v) {
super(v);
v.setOnClickListener(this);
@VibeMage
VibeMage / Android @IntDef.java
Last active January 17, 2020 03:36
[@IntDef replace enum]#Android
@IntDef({Status.IDLE, Status.PROCESSING, Status.DONE, Status.CANCELLED})
@Retention(RetentionPolicy.SOURCE)
@interface Status {
int IDLE = 0;
int PROCESSING = 1;
int DONE = 2;
int CANCELLED = 3;
}
@VibeMage
VibeMage / EachDirectoryPath.md
Last active January 17, 2020 03:35 — forked from granoeste/EachDirectoryPath.md
[Get the each directory path] #Android

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

@VibeMage
VibeMage / RecyclerView.Java
Last active July 24, 2018 09:31
[RecyclerView onItemClickListener]#Android
public class ReactiveAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
String[] mDataset = { "Data", "In", "Adapter" };
private final PublishSubject<String> onClickSubject = PublishSubject.create();
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final String element = mDataset[position];
holder.itemView.setOnClickListener(new View.OnClickListener() {