Skip to content

Instantly share code, notes, and snippets.

@Ray33
Ray33 / WebViewLoading.java
Created November 18, 2016 07:42
Some webview settings to load web pages
private void initWebView() {
mWebView.setWebViewClient(new WebViewClientImpl());
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl(mUrl);
}
@Ray33
Ray33 / readme.md
Last active March 14, 2023 23:16

Create letsencrypt SSL (ECDSA) + Ngnix configuration

Verify dependencies prerequisites

Update OS

sudo yum update && sudo yum upgrade

Git Version update

@Ray33
Ray33 / gist:ba189a729d81babc99d7cef0fb6fbcd8
Last active July 22, 2022 10:50 — forked from SamCyanide/gist:780afff4c3e1a9e105264c2a476e037c
Amazon Elastic Network Adapter (ENA) on CentOS 7
sudo su
yum --enablerepo=extras install epel-release
yum -y install patch dkms kernel-devel perl
yum update
#Required for kernel num 5:
yum --enablerepo=elrepo-kernel -y install kernel-ml-devel
reboot
@Ray33
Ray33 / install_openresty.sh
Last active August 3, 2020 20:26
devOps - replace old nginx with openresty
#Based on: https://www.linuxsecrets.com/1631-complete-guide-installing-openresty-a-nginx-full-fledged-web-server-on-redhat-scientific-linux-debian
#Get openSSL version that you want to compile with
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.1.1f.tar.gz
tar zxvf openssl-1.1.1f.tar.gz
#Get Open resty version
cd /tmp
wget https://openresty.org/download/openresty-1.17.8.2.tar.gz
public static String getDefaultUserAgentString(Context context) {
if (Build.VERSION.SDK_INT >= 17) {
return NewApiWrapper.getDefaultUserAgent(context);
}
try {
Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class);
constructor.setAccessible(true);
try {
WebSettings settings = constructor.newInstance(context, null);
@Ray33
Ray33 / YourApplicationClass.java
Last active March 8, 2019 03:20
An Asynchronous method to get user google advertising id.
//callback for user id:
//Either takes the user's advertiserId or creates a unique ID, if
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(YourApplicationClass.this);
if (!adInfo.isLimitAdTrackingEnabled()) {//if user hasn't opt-out
return adInfo.getId();
}else{
@Ray33
Ray33 / UserCountryUtil.java
Created May 17, 2017 12:13
Get user country by network
/**
* Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
* @param context Context reference to get the TelephonyManager instance from
* @return country code or null
*/
public String getUserCountry(Context context) {
try {
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = tm.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
@Ray33
Ray33 / proguard-rules.pro
Last active September 19, 2018 11:03
Mobitech content sdk pro guard
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public class io.mobitech.**
@Ray33
Ray33 / GlideLoading.java
Last active May 23, 2018 06:30
Glide to handle big images
GlideApp.with(context.getApplicationContext()).load(url).fallback(R.drawable.loading)
.into((BaseTarget) new BaseTarget<BitmapDrawable>() {
@Override
public void onResourceReady(@NonNull BitmapDrawable resource, @Nullable Transition<? super BitmapDrawable> transition) {
showNotification(context, newsArticle, ((BitmapDrawable) resource).getBitmap());
}
@Override
public void getSize(@NonNull SizeReadyCallback cb) {
@Ray33
Ray33 / NetworkHelper.java
Created March 14, 2018 09:39
Android Get with redirect support
public static void httpGetWithRedirectSupport(final Context context, String url){
Volley.newRequestQueue(context).add(new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
// Do nothing
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
if (volleyError.networkResponse != null && (volleyError.networkResponse.statusCode == 302 || volleyError.networkResponse.statusCode == 301)) {