Skip to content

Instantly share code, notes, and snippets.

View vishvendra01's full-sized avatar
😃
Kaizen

Vishvendra Singh vishvendra01

😃
Kaizen
View GitHub Profile
@vishvendra01
vishvendra01 / File Validation
Created November 3, 2014 13:29
Check whether a given file exists or not
# 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
@vishvendra01
vishvendra01 / python pickle
Created November 4, 2014 06:52
python pickle working example
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
@vishvendra01
vishvendra01 / iconshide
Created November 14, 2014 08:50
python script to hide and unhide desktop icons on gnone3 when nemo is primary file manager
#!/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)
@vishvendra01
vishvendra01 / editEditext
Last active August 29, 2015 14:23
Disable and enable edittext for editing
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);
@vishvendra01
vishvendra01 / netavail
Created June 22, 2015 13:23
check whether internet connection available or not
/**
*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) {
@vishvendra01
vishvendra01 / Signup2Activity.java
Created June 23, 2015 05:41
Signup Activity code which contains error
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;
@vishvendra01
vishvendra01 / timestamp2date.java
Created September 10, 2015 06:54
convert time-stamp to date
// 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();
@vishvendra01
vishvendra01 / VideoChooserDialog.java
Last active December 30, 2022 21:19
android code to choose video using camera or gallery
// 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
@vishvendra01
vishvendra01 / get_time_difference.java
Created September 18, 2015 11:32
get time difference of two timstamps, convert date format to a timestamp
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;
@vishvendra01
vishvendra01 / res_batch_rename.java
Created September 19, 2015 08:48
python script to rename br given android slices
#!/usr/bin/env python
import os
import logging
logging.basicConfig(level=logging.DEBUG)
def parse_nautilus_environment():
result = {
'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS' : [],