Skip to content

Instantly share code, notes, and snippets.

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 / 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 / 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 / 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
@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 / 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 / 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)) {
@Ray33
Ray33 / NewsArticlesAdapter.java
Created December 6, 2017 14:12
Call visibility URL on bind
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
NewsArticle newsArticle = newsArticles.get(i);
final String articleVisibleUrl = newsArticle.visibleUrl;
if (!TextUtils.isEmpty(articleVisibleUrl) && newsArticle.isPromoted) {
Volley.newRequestQueue(context).add(new StringRequest(articleVisibleUrl, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
// Do nothing
@Ray33
Ray33 / visibility.js
Last active January 24, 2018 07:10
Visibility call via HTML
//initialize variables
var visible_urls = new Map();
var fired_urls = [];
//When news item is created, add it's id and the it's visibilityUrl to map
visible_urls.set(news_item.id, news_item.visibleUrl);
//call the url in background
function open_visible_url(url) {
if (url){
@Ray33
Ray33 / IsDeviceLowEnd.java
Last active November 15, 2017 14:01
Check if device is low end.Low end= Low Memory || Bad Network
private boolean getIsLowDevice(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
double availableMegs = (double)mi.availMem / 1048576d;
String networkType = getNetworkClass(context);
return "2G".equalsIgnoreCase(networkType) && availableMegs > 400;
}