This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check whether given file exist or not and readable too | |
import os | |
# first approach | |
# I think it is best practice to use this approach | |
def validate_file(file_name): | |
if os.path.isfile(file_name) and os.access(file_name, os.R_OK): | |
return True | |
else: | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
favorite_color = {"lion":"yellow", "kitty":"red"} | |
pickle.dump(favorite_color, open("save.p", "wb")) | |
favorite_color = pickle.load( open("save.p", "rb")) | |
# in python, you can speed up pickle access with cPickle | |
# in python 3, importing pickle will automatically use the | |
# accelerated version if available |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess as sp | |
#nemo | |
output = sp.check_output("gsettings get org.nemo.desktop show-desktop-icons", shell=True).strip("\n") | |
print output.strip("\n") | |
if output == "true": | |
sp.call("gsettings set org.nemo.desktop show-desktop-icons false", shell=True) | |
elif output == "false": | |
sp.call("gsettings set org.nemo.desktop show-desktop-icons true", shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
etKeyListeners = new ArrayList<>(7); | |
editFieldsList = new ArrayList<>(7); | |
btn_save = (Button) findViewById(R.id.btn_save); | |
btn_cancel = (Button) findViewById(R.id.btn_cancel); | |
save_cancel_layout = (LinearLayout) findViewById(R.id.ll_update_btn); | |
save_cancel_layout.setVisibility(View.GONE); | |
user_email = (EditText) findViewById(R.id.et_user_email); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*Check internet connectivity by ping | |
*/ | |
public Boolean isOnline() { | |
try { | |
p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com"); | |
int returnVal = p1.waitFor(); | |
boolean reachable = (returnVal == 0); | |
if (reachable) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ets.medecord; | |
import android.app.Activity; | |
import android.app.AlertDialog; | |
import android.app.ProgressDialog; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.net.ConnectivityManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// convert time-stamp to date | |
Calendar cal = Calendar.getInstance(Locale.ENGLISH); | |
cal.setTimeInMillis(Long.valueOf(data.getDate())* 1000); | |
Log.d("dateinstamp", data.getDate()); | |
String date = DateFormat.format("dd-MM-yyyy", cal).toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to show a dialog to select video file | |
private void showVideoChooserDialog() { | |
final CharSequence[] options = { "From Camera", "From Gallery", | |
"Cancel" }; | |
AlertDialog.Builder builder = new AlertDialog.Builder(this); | |
builder.setTitle("Upload!"); | |
builder.setItems(options, new DialogInterface.OnClickListener() { | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getTimeDifference(String lastView) throws ParseException { | |
Long curTimeInMill = System.currentTimeMillis(); | |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
format.setTimeZone(TimeZone.getTimeZone("UTC")); | |
Date parsedDate = format.parse(lastView); | |
Long lastViewInMillis = parsedDate.getTime(); | |
Log.d("lastView", lastView); | |
Log.d("lastViewinMillis", String.valueOf(lastViewInMillis)); | |
long diff = curTimeInMill - lastViewInMillis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
def parse_nautilus_environment(): | |
result = { | |
'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS' : [], |
OlderNewer