Skip to content

Instantly share code, notes, and snippets.

View sreejithbnaick's full-sized avatar

Sreejith B Naick sreejithbnaick

  • HealthifyMe
  • Bangalore
View GitHub Profile
@sreejithbnaick
sreejithbnaick / Android TIPS And TRICKS
Created January 3, 2015 14:32
Android Tips and Tricks - Recipes
Android Tips and Tricks
1) ImageView setCropToPadding by code when setting CENTER_CROP as scaleType:
====================================================================
Field field;
try {
field = ImageView.class.getDeclaredField("mCropToPadding");
field.setAccessible(true);
field.set((ImageView) convertView, true);
@sreejithbnaick
sreejithbnaick / Self Signed SSL Certifcate Generation
Created January 16, 2015 07:06
Self Signed SSL Certifcate Generation
$ openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
...
$ openssl rsa -passin pass:x -in server.pass.key -out server.key
writing RSA key
$ rm server.pass.key
$ openssl req -new -key server.key -out server.csr
...
@sreejithbnaick
sreejithbnaick / WikipediaFeatureArticle.java
Last active March 24, 2016 17:44
Java code to get Wikipedia Article of the day (Using JSOUP)
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
public class WikipediaFeatureArticle {
@sreejithbnaick
sreejithbnaick / Shell Script: Multiple File Text Replace
Created May 7, 2016 07:59
Shell Script: Multiple Files String Replace
for y in `ls *`
do
echo $y
sed -i 's|old-text-here|new-text-here|g' "$y"
done
@sreejithbnaick
sreejithbnaick / openssl encrpyt decrypt
Created June 14, 2016 13:28
openssl encrpyt decrypt
encryption:
openssl rsa/des/des3 -e -salt -pass pass:passphrase -in input_file -out output_file
decryption:
openssl rsa/des/des3 -d -salt -pass pass:pass-phrase -in input_file -out output_file
@sreejithbnaick
sreejithbnaick / SSH Key Generation
Created June 14, 2016 13:36
SSH Key Generation
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
1) Nine patch
It allows extension in 9 ways,
i.e. 4 corners that are unscaled,
4 edges that are scaled in 1 axis,
and the middle one that can be scaled into both axes.
2) Implicit and explicit intents
Implicit intents do not name a specific component,
but instead declare a general action to perform, which allows a component from another app to handle it.
eg: default system intents like sms,call,sendTo,view etc
https://docs.oracle.com/javase/8/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html
Java Thread Primitive Deprecation
Why is Thread.stop deprecated?
Because it is inherently unsafe. Stopping a thread causes it to unlock all the monitors that it has locked. (The monitors are unlocked as the ThreadDeath exception propagates up the stack.) If any of the objects previously protected by these monitors were in an inconsistent state, other threads may now view these objects in an inconsistent state. Such objects are said to be damaged. When threads operate on damaged objects, arbitrary behavior can result. This behavior may be subtle and difficult to detect, or it may be pronounced. Unlike other unchecked exceptions, ThreadDeath kills threads silently; thus, the user has no warning that his program may be corrupted. The corruption can manifest itself at any time after the actual damage occurs, even hours or days in the future.
Couldn't I just catch the ThreadDeath exception and fix the damaged object
Process & Threads
* volatile - java keyword indicating that a variable's value will be modified by different threads. (for synchronization)
* Types of process & in the order of importance:
- Foreground process- running Activity, Bounded services, Foreground service(startForeground),Service with its own lifeCycle, Broadcast receiver
- Visible process - foreground activity(visible, but onPause called), service bound to visible/foreground activity
- Service process - A process that is running a service that has been started with the startService() method,eg music in bg,download
- Background process - background activity(onstop called)
- Empty process - A process that doesn't hold any active application components, for caching purposes, to improve startup time
Peripheral Mode [ Supported above api 21 only (M and above, some devices including google nexus devices) ]
===============
BluetoothManager = #getSystemService(BLUETOOTH_SERVICE);
BluetoothAdaper = BluetoothManager#getAdapter();
Server:
------
BluetoothGattServer = BluetoothManager#openGattServer(Context,BluetoothGattServerCallback)