Skip to content

Instantly share code, notes, and snippets.

@davidalbers
davidalbers / exowrapper.kt
Last active Aug 7, 2021
Android: play /raw resource with Exoplayer
View exowrapper.kt
val player = ExoPlayerFactory.newSimpleInstance(context, DefaultTrackSelector())
val rawDataSource = RawResourceDataSource(context)
// open the /raw resource file
rawDataSource.open(DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.brown)))
// create a media source with the raw DataSource
val mediaSource = ExtractorMediaSource.Factory(DataSource.Factory { rawDataSource })
.createMediaSource(rawDataSource.uri)
View DelayAutoCompleteTextView
public class DelayAutoCompleteTextView extends AutoCompleteTextView {
private static final int MESSAGE_TEXT_CHANGED = 100;
private static final int DEFAULT_AUTOCOMPLETE_DELAY = 1000;
private int mAutoCompleteDelay = DEFAULT_AUTOCOMPLETE_DELAY;
private static class AvoidingMemoryLeakHandler extends Handler {
private final WeakReference<DelayAutoCompleteTextView> delayAutoCompleteTextViewWeakReference;
@geniushkg
geniushkg / filter category in result retrofit list
Created Sep 27, 2016
sample gist to filter content from retrofit response
View filter category in result retrofit list
// this is retrofit response
Eventlist eventlist = response.body();
List<Website> websites = eventlist.getWebsites(); // website is POJO class for even as per api
List<Website> filteredWebsite = new ArrayList<Website>(); // empty list new
for(Website temp:websites){
if(temp.getCategory().equalsIgnoreCase(sortType.name())){
filteredWebsite.add(temp); // sortType.name() is BOT or Competitive or whichever selected
}
}
View ConnectionUtils.java
package ru.mobileup.grushasdk.utils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
/**
* @author Vasili Chyrvon (vasili.chyrvon@gmail.com)
@JIghtuse
JIghtuse / echo_server.cxx
Last active Jun 17, 2021
echo server (select, C++)
View echo_server.cxx
#include <array>
#include <cassert>
#include <iostream>
#include <set>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>
@danielmai
danielmai / ForecastListToDetailTest.java
Created Dec 18, 2015
Espresso test for Sunshine. Demo for the Android Testing webcast in the Android Developer Nanodegree.
View ForecastListToDetailTest.java
package com.example.android.sunshine.app.ui;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.example.android.sunshine.app.MainActivity;
import com.example.android.sunshine.app.R;
import org.junit.Rule;
View gist:e71253f6c41179754347
yes you can
AppBarLayout appBar;
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if(verticalOffset > -300) {
collapsedAppBar.setTitleEnabled(false);
}
else {
View store_api_keys.md

1. Store api keys in a xml file

Put xml file "api_keys.xml" in the directory "res/value/".

api_keys.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="THE_MOVIE_DB_API_TOKEN">XXXXX</string>
</resources>
@marty-wang
marty-wang / gist:5a71e9d0a6a2c6d6263c
Last active Jul 21, 2021
Compile and deploy React Native Android app of Release version to device.
View gist:5a71e9d0a6a2c6d6263c
Disclaimer: The instructions are the collective efforts from a few places online.
Nothing here is my original. But I want to put them together in one place to save people from spending the same time as I did.
First off, bundle.
==================
1. cd to the project directory
2. Start the react-native packager if not started
3. Download the bundle to the asset folder:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
View wtf.js
/* VT100 terminal reset (<ESC>c) */
console.log('\033c');
/* numbers comparations */
> '2' == 2
true
> '2' === 2