Skip to content

Instantly share code, notes, and snippets.

Deepak Singh spidergears

View GitHub Profile
View AndroidPermissionsDynamic.java
private final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 123
pricate final String writeExternalStorageRationale = "You haven't given us permission to use Storage, please enable the permission to store images.";
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode){
case WRITE_EXTERNAL_STORAGE_REQUEST_CODE:
if (grantResults[0] != PackageManager.PERMISSION_GRANTED)
captureImage();
else{
View handlePermissionResult.java
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == WRITE_EXTERNAL_STORAGE_REQUEST_CODE){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
captureImage();
else{
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE))
showRationaleDialog();
else
Toast.makeText(MainActivity.this, "You need to allow permission to Write to External Storage", Toast.LENGTH_LONG).show();
View captureImageWithSupport.java
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
=> ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
=> ActivityCompat.requestPermissions(MainActivity.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)
=> ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
View captureImage.java
private final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 123
private void takePhoto() {
//Make sure we have permission to write to external storage
int hasWriteExternalStoragePermission = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteExternalStoragePermission == PackageManager.PERMISSION_GRANTED)
captureImage()
else
requestPermissionWriteToLocalStorage();
}
View build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 10
targetSdkVersion 23
View AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application ...>
...
</application>
View ytpp_content_script.js
chrome.extension.onMessage.addListener(function(message, sender, sendResponse) {
if(message.action == "toggle_playback"){
play_pause_button = document.getElementsByClassName('ytp-play-button ytp-button')[0]
if(play_pause_button){
play_pause_button.click();
}
}
});
View ytpp_background_script.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.query({}, function(tabs){
for (var i=0; i < tabs.length; i++) {
if (/https?:\/\/www\.youtube\.com/.test(tabs[i].url)) {
chrome.tabs.sendMessage(tabs[i].id, {action: "toggle_playback"}, function(response) {});
}
}
})
});
View manifest.json
{
"manifest_version": 2,
"name": "YTPP",
"short_name": "YTPP",
"version": "0.1",
"description": "YTPP: YouTube Play/Pause without switching tabs",
"icons": {"128": "icon.png", "48": "icon_48.png", "16": "icon_16.png" },
"author": {"name": "spidergears", "twitter_handle": "spider_gears", "github": "http://github.com/spidergears"},
"browser_action": { "default_icon": "icon.png", "default_title": "YTPP"},
@spidergears
spidergears / git-create.bash
Last active Jul 11, 2016
Bash script to create empty github repository
View git-create.bash
git-create(){
repo_name=$1
dir_name=`basename $(pwd)`
if [ "$repo_name" = "" ]; then
echo -n "Repo name [$dir_name]?: "
read repo_name
fi
if [ "$repo_name" = "" ]; then
You can’t perform that action at this time.