Skip to content

Instantly share code, notes, and snippets.

View adityabhaskar's full-sized avatar
👣
à pied

Aditya adityabhaskar

👣
à pied
View GitHub Profile
@adityabhaskar
adityabhaskar / dependencyGraph-mermaid.gradle
Last active May 17, 2023 17:32
Dependency graphs in a multi module project, in mermaid format for automatic rendering on Github
class GraphDetails {
LinkedHashSet<Project> projects
LinkedHashMap<Tuple2<Project, Project>, List<String>> dependencies
ArrayList<Project> multiplatformProjects
ArrayList<Project> androidProjects
ArrayList<Project> javaProjects
ArrayList<Project> rootProjects
// Used for excluding module from graph
public static final SystemTestName = "system-test"
@adityabhaskar
adityabhaskar / withPrefs.kt
Created November 27, 2021 16:23
Access SharedPreferences without StrictMode warnings
private fun <T> withPrefs(context: Context, callback: SharedPreferences.() -> T): T {
val oldPolicy = StrictMode.allowThreadDiskWrites()
val output = context.applicationContext
.getSharedPreferences(BILLING_STORAGE_NAME, Context.MODE_PRIVATE)
.callback()
StrictMode.setThreadPolicy(oldPolicy)
@adityabhaskar
adityabhaskar / pinWidget.kt
Created December 7, 2020 11:29
Pinning an Android widget programmatically
private fun pinWidget(context: Context) {
val appWidgetManager = context.getSystemService(AppWidgetManager::class.java) ?: return
val myProvider = ComponentName(context.applicationContext, TaskListWidget::class.java)
if (!appWidgetManager.isRequestPinAppWidgetSupported) {
Timber.d("Widgets not supported")
return
}
// Create the PendingIntent object only if your app needs to be notified
@adityabhaskar
adityabhaskar / isOnline.kt
Created August 21, 2020 15:31
Extension function to check if the device is connected to the internet
/**
* Whether the device has an active connection to the internet
*/
val Context.isConnected: Boolean
get() {
val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.activeNetwork ?: return false
return cm.getNetworkCapabilities(activeNetwork)
?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) == true
@adityabhaskar
adityabhaskar / LICENSE
Created July 16, 2020 14:08 — forked from dotproto/LICENSE
MV3 webRequest demo. To view the console, you may need to manually open devtools for the service worker. On Chrome, visit chrome://serviceworker-internals and search for the service worker registered to `chrome-extension://<extension-id>/` where extension-id is the ID of your extension.
Copyright 2020 Google LLC
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
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@adityabhaskar
adityabhaskar / dropShadow.sh
Last active July 10, 2020 07:04
Command line image utils - SVG to PNG, Drop shadow
# Add macOS window screenshot style dropshadow
convert inputfile.png \( +clone -background Black -shadow 50x25+0+20 \) +swap -background none -layers merge +repage outputFile.png
@adityabhaskar
adityabhaskar / main.css
Created May 19, 2020 15:16
Basic centred webpage css
body {
/* content width is 2x 350px */
margin: auto calc(50% - 350px);
color: rgba(0, 0, 0, .8);
font-size: 16px;
font-family: system-ui, 'Roboto', sans-serif;
line-height: 1.6;
}
@media (max-width: 767px) {
@adityabhaskar
adityabhaskar / Utils.kt
Created November 12, 2019 15:58
Android Check Internet Connection
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.content.Context
object Utils {
internal fun isOnline(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.activeNetwork ?: return false
val capabilities = cm.getNetworkCapabilities(activeNetwork) ?: return false
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
@adityabhaskar
adityabhaskar / BitFlags.kt
Created October 4, 2019 16:46 — forked from LouisCAD/BitFlags.kt
Allows simple bit flags operation on int values in kotlin. Inspired by: http://stackoverflow.com/a/40588216/4433326
@file:Suppress("NOTHING_TO_INLINE")
import kotlin.experimental.and // Used for Byte
import kotlin.experimental.inv // Used for Byte
import kotlin.experimental.or // Used for Byte
inline fun Int.hasFlag(flag: Int) = flag and this == flag
inline fun Int.withFlag(flag: Int) = this or flag
inline fun Int.minusFlag(flag: Int) = this and flag.inv()
@adityabhaskar
adityabhaskar / gist:529a510de18822a438f9a577adeb3255
Created September 9, 2019 15:36 — forked from Pretz/gist:822036
xAuth in Android for Instapaper using Signpost
protected String[] doInBackground(String... credentials) {
String consumer_secret = mActivity.getString(R.string.oauth_consumer_secret);
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("https://www.instapaper.com/api/1/oauth/access_token");
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(mActivity.getString(R.string.oauth_consumer_key),
consumer_secret);
List<BasicNameValuePair> params = Arrays.asList(
new BasicNameValuePair("x_auth_username", credentials[0]),
new BasicNameValuePair("x_auth_password", credentials[1]),
new BasicNameValuePair("x_auth_mode", "client_auth"));