Skip to content

Instantly share code, notes, and snippets.

View captswag's full-sized avatar
👘
3 time employee of the month

Anjith Sasindran captswag

👘
3 time employee of the month
View GitHub Profile
@captswag
captswag / Truss.java
Last active April 30, 2021 16:13 — forked from JakeWharton/Truss.java
Rewrote Jake Wharton's wrapper of SpannableStringBuilder in Kotlin
import android.text.SpannableStringBuilder
import android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE
import java.util.ArrayDeque
import java.util.Deque
// https://gist.github.com/JakeWharton/11274467
public class Truss {
private val builder: SpannableStringBuilder = SpannableStringBuilder()
private val stack: Deque<Span> = ArrayDeque()
void fetchTopTrendingList() {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BuildConfig.SERVER_URL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
@captswag
captswag / ReflectionExample.java
Last active November 9, 2017 16:56
Reflection in Java
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Constructor;
class ReflectionExample {
public static void main(String args[]) throws Exception {
// Examining & constructing object for Test class at runtime
Class<?> clazz = Class.forName("Test");
Test test = (Test) clazz.newInstance();
void getNowPlayingMovies() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
TmdbInterface tmdbInterface = retrofit.create(TmdbInterface.class);
Observable<HashMap<Integer, String>> genresListResponseObservable =
/**
* Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
* Parameters:
* anObject The object to compare this String against
* Returns:
* true if the given object represents a String equivalent to this string, false otherwise
* See also:
* compareTo(java.lang.String)
* equalsIgnoreCase(java.lang.String)
*/
@captswag
captswag / FacebookIntent.java
Created May 7, 2015 11:41
Android, java code for opening facebook profile of a user in the facebook application, if the user has it installed, or open the profile in the web browser.
/*
* Go to https://graph.facebook.com/<user_name_here>
* Copy your id
* This will open up facebook app if the user has it installed
* Otherwise it will open facebook in the browser
*/
public Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
@captswag
captswag / SharedPreferencesExample.java
Last active August 29, 2015 14:20
Simplest example of using SharedPreferences in Android to store key-pair values.
String message = "Hi";
static String fileName = "shared_string";
SharedPreferences sharedPreferences;
sharedPreferences = getSharedPreferences(fileName, MODE_PRIVATE);
//Inserting
SharedPreferences.Editor = sharedPreferences.edit();
editor.putString("message", message);
editor.commit();
@captswag
captswag / HelloWorld.java
Last active August 29, 2015 14:19
Trying out Gist with a sample hello world program in Java
class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}