Skip to content

Instantly share code, notes, and snippets.

View surajsau's full-sized avatar
🙇‍♂️
よろしくお願いします!

Suraj Kumar Sau surajsau

🙇‍♂️
よろしくお願いします!
View GitHub Profile
@surajsau
surajsau / DetectSoftKeyboardLinearLayout.java
Created June 15, 2016 06:12
LinearLayout which identifies whether soft keyboard is visible or hidden
import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.LinearLayout;
/**
* Created by suraj on 15/6/2016.
*
* This linear layout is used to listen to visibility of the soft keyboard.
@surajsau
surajsau / activity_main.xml
Created June 30, 2016 04:36
'scroll | enterAlways' behaviour without using CoordinatorLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/rootView"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
@surajsau
surajsau / FilepathToUri.java
Created July 18, 2016 14:51
Getting filePath from Uri
@SuppressLint("NewApi")
private static String getRealPathFromUri(boolean isKitKat, final Context context, final Uri uri) {
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
@surajsau
surajsau / ServiceGenerator.java
Created August 24, 2016 16:53
Boilerplate code for Retrofit in code
import java.io.IOException;
import in.surajsau.popularmovies.IConstants;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
@surajsau
surajsau / SamplePreferece.java
Created July 18, 2017 12:22
Sample Preference class for all Android projects
public class SamplePreference {
private static SharedPreferences sharedpreferences;
public static SharedPreferences init(Context appCtx, String file) {
sharedpreferences = appCtx.getSharedPreferences(file,
Context.MODE_PRIVATE);
return sharedpreferences;
@surajsau
surajsau / image_download.sh
Created September 10, 2018 11:09
Serial Image Downloader
#!/bin/bash
i=0
limit=<MAX_LIMIT>
while [ $i -lt $limit ]
do
if [ $i -lt 10 ]
then
@surajsau
surajsau / cases.js
Last active January 7, 2019 06:48
Cases Intent (Dailyrounds Assitant)
/**
* This handles 'Latest 10 cases in Radiology' from the user. It receives
* $rounds_pref (from rounds_preference entity) as in which speciality is being asked for,
* $cases tells total number of cases asked for
* $is_best_cases tells whether the user wants 'Top' or 'Best' cases
*/
app.intent('cases', (conv, {rounds_pref, cases, is_best_cases}) => {
//default 5 cases
if(!cases)
cases = 5;
@surajsau
surajsau / casesrequest.js
Created January 4, 2019 11:32
Cases Request function (DailyRounds Assistant)
const casesRequest = (rounds, skipCount, conv) => {
const timestamp = new Date().getTime();
const options = {
method: 'GET',
url: `http://keanuisimmortal.com/v1/talk?topics=${rounds.id}&limit=${skipCount}`,
headers: {
'Content-Type': 'application/json',
...
}
};
@surajsau
surajsau / cases_speciality_ask_yes.js
Last active January 7, 2019 06:45
Follow Up 'Yes' intent
/**
* This handles the situation when agrees to save his/her speciality
* preference or wants to change his/her speciality preference.
*/
app.intent(['rounds_preference_yes', 'rounds_preference_change', 'cases_speciality_ask_yes'], (conv) => {
conv.ask('Sure, so which speciality would you prefer to see?');
conv.ask(new Suggestions('DailyRounds', 'Radiology Rounds', 'Cardiology Rounds'));
});
@surajsau
surajsau / cases_speciality_ask_no.js
Last active January 7, 2019 06:35
'No' Follow Up intent DailyRounds Assistant
/**
* This handles the situation when user refuses to save his/her
* speciality preference. In this case, we use the fallback 'primary'.
* 'cases-followup' context has exhausted 1 lifespan. Since, it has a
* total of 2, we are safe to proceed with using it's parameters
* without first checking for availability of context.
*/
app.intent('cases_speciality_ask_no', (conv) => {
conv.ask('Not an issue, you can always save your preference later.');