Skip to content

Instantly share code, notes, and snippets.

View AntonioDiaz's full-sized avatar
🤓

Antonio Diaz Arroyo AntonioDiaz

🤓
View GitHub Profile
@AntonioDiaz
AntonioDiaz / Update01.java
Created October 14, 2022 06:01
Update Mongo DB
@Test
public void testReplaceDocument() {
MongoCollection<Document> artists = testDb.getCollection("artists");
Bson queryFilter = new Document("_id", band1Id);
Document myBand = artists.find(queryFilter).iterator().tryNext();
Assert.assertEquals(
"Make sure that the band created in the database is"
+ " the same as the band retrieved from the database",
bandOne,
myBand);
@AntonioDiaz
AntonioDiaz / generateInputStream.kt
Created January 18, 2021 12:26
generateInputStream for testing
private fun generateInputStream(): InputStream {
val bytesOutputStream = ByteArrayOutputStream()
val out = ZipOutputStream(bytesOutputStream, Charset.defaultCharset())
val writeEntry = ZipEntry("test.csv")
out.putNextEntry(writeEntry)
out.write("content".toByteArray())
out.closeEntry()
out.close()
return ByteArrayInputStream(bytesOutputStream.toByteArray())
}
@AntonioDiaz
AntonioDiaz / DownloadPodcast.kt
Created August 14, 2018 11:17
Script download poscast.
package com.examples
import com.beust.klaxon.JsonArray
import com.beust.klaxon.JsonObject
import com.beust.klaxon.Parser
import com.examples.DownloadPodcast.Companion.NEXT_PUB_DATE_PUNTA_NORTE
import com.examples.DownloadPodcast.Companion.URL_PUNTA_NORTE
import java.io.BufferedInputStream
import java.io.File
import java.io.FileOutputStream
@AntonioDiaz
AntonioDiaz / toolbar_main.xml
Created March 24, 2017 15:45
Add view inside toolbar.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:contentInsetLeft="0dp"
@AntonioDiaz
AntonioDiaz / CalendarAdapter.java
Created March 23, 2017 15:44
BaseExpandableListAdapter example
package com.adiaz.expandablelist;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import java.util.List;
@AntonioDiaz
AntonioDiaz / build.gradle
Created March 14, 2017 07:22
Grade task dependences
/*
Now that we can declare tasks, it's time to think about the relationships
between tasks. For example, in a Java build, we can't JAR up our library
before compiling our sources. We model these relationships by task
dependencies and ordering.
We'll discuss three ways to configure the relationships between tasks:
`dependsOn`, `finalizedBy`, and `mustRunAfter`.
@AntonioDiaz
AntonioDiaz / MainActivity.java
Last active December 30, 2021 10:46
AsyncTaskLoader Example
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@AntonioDiaz
AntonioDiaz / AndroidManifest_PROVIDER.xml
Last active January 5, 2017 07:36
Declare Content Provider and allow access from another app.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.sunshine.app">
<application>
<activity>...</activity>
<provider
android:name=".data.WeatherProvider"
android:authorities="com.example.android.sunshine.app"
android:enabled="true"
android:exported="true"
android:permission="com.myapp.OhhhhDiosito">
@AntonioDiaz
AntonioDiaz / ForecastCursorAdapter.java
Last active January 4, 2017 07:10
CursorAdapter implementation example.
public class ForecastCursorAdapter extends CursorAdapter {
public ForecastCursorAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
}
/** Remember that these views are reused as needed. */
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.list_item_forecast, parent, false);
@AntonioDiaz
AntonioDiaz / CursorLoader.java
Last active December 19, 2020 19:31
CursorLoader example in a Fragment
package com.example.android.sunshine.app;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
public class ForecastFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {