Skip to content

Instantly share code, notes, and snippets.

View JosiasSena's full-sized avatar
🏠
Working from home

Josias Sena JosiasSena

🏠
Working from home
View GitHub Profile
@JosiasSena
JosiasSena / get_supported_android_devices.js
Last active December 7, 2016 21:54
get supported devices from developer portal
$(document).ready(function () {
var interval = setInterval(function () {
myTimer();
}, 5000);
function myTimer() {
var manufacturers = [];
var devices = [];
var elements = document.getElementsByTagName("li");
@JosiasSena
JosiasSena / rando_btn_rgb.py
Last active October 2, 2016 02:22
Raspberry Pi - Display red, green, or blue randomly on button press
import random
import time
import RPi.GPIO as GPIO
# Constants
RUNNING = True
SLEEP_TIME = .2 # in seconds
FREQUENCY_ON = 100 # Hz
FREQUENCY_OFF = 0 # Hz
@JosiasSena
JosiasSena / removeWhiteSpaces
Created July 15, 2016 23:26
Removes all white spaces from string
/**
* Removes all white spaces from string
*
* @param text - text to remove white spaces from
* @return - text without any whitespaces
*/
public static String removeWhiteSpaces(String text) {
return text.replaceAll("\\s+", "");
}
@JosiasSena
JosiasSena / gist:c257013bb222ad2430334468bd442ea1
Created July 15, 2016 23:26
Check if the string contains a number or a special character
/**
* Check if the string contains a number or a special character
*
* @param text - string to check
* @return - true if it contains a number or a special character, else false
*/
public boolean textContainsSpecialCharsOrNumbers(String text) {
return !text.matches("^[a-z A-Z]+$");
}
@JosiasSena
JosiasSena / getCurrentDevicePhoneNumber
Created July 15, 2016 23:25
Get the current devices phone number
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = telephonyManager.getLine1Number();
@JosiasSena
JosiasSena / goToAppSettings
Created July 15, 2016 23:24
go to the settings for the current application
public static void goToAppSettings(final Context context) {
final Uri uri = Uri.fromParts("package", context.getPackageName(), null);
final Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
context.startActivity(intent);
}
@JosiasSena
JosiasSena / isGpsEnabled
Created July 15, 2016 23:23
check if GPS is enabled
/**
* Returns the current enabled/disabled status of the GPS provider.
* <p/>
* If the user has enabled GPS in the Settings menu, true
* is returned otherwise false is returned
*/
public static boolean isGpsEnabled(final Context context) {
final LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
@JosiasSena
JosiasSena / getStringFromAssetFile
Created July 15, 2016 23:22
Load string from a file in Asset folder
public static String getStringFromAssetFile(final Context context, final String filename) {
final int MAX_BUFF = 1024 * 100;
final InputStream is;
final InputStreamReader isr;
final BufferedReader br;
String resultData = "";
try {
final AssetManager am = context.getAssets();
@JosiasSena
JosiasSena / hideKeyboard
Created July 15, 2016 23:22
Hide keyboard in Android
final InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
@JosiasSena
JosiasSena / genFbHash.txt
Last active July 15, 2016 23:17
Generate KeyHash for Facebook SDK
Generate KeyHash for Facebook SDK
1. First open a terminal (open a command prompt in windows).
2. Navigate in the terminal to the directory where your Android debug.keystore is stored.
3. Mostly it will located under “/Users/user_name/.android/” (In Windows will be C:\Documents and Settings\.android).
4. Once you are in the “.android” directory, run the following command.keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

Note: “androiddebugkey” can be the username for the keystone file and “debug.keystore” can be the name of the keynote file
1. When it prompts you for a password, type android and hit Enter