Skip to content

Instantly share code, notes, and snippets.

View guptasanchit90's full-sized avatar
💻
Living at Work

Sanchit Gupta guptasanchit90

💻
Living at Work
View GitHub Profile
@guptasanchit90
guptasanchit90 / app.js
Created June 6, 2016 06:40
Simple Image hosting from file system in Node.js using express routes
var express = require('express');
var app = express();
var fs = require('fs');
app.get('/get', function (req, res) {
res.sendFile(__dirname + '/' + req.query.type + '/' + req.query.name);
})
app.get('/list', function (req, res) {
@guptasanchit90
guptasanchit90 / SplashScreen.java
Created June 7, 2016 09:32
Simple Splash screen
public class SplashScreen extends Activity {
private Handler mHandler;
private Runnable myRunnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Just create simple XML layout with i.e a single ImageView or a custom layout
app.run(function($window, $rootScope) {
$rootScope.online = navigator.onLine;
/**
Generate event offline when user disconnects from Internet
$scope.$watch('offline', function(newStatus) { ... });
**/
$window.addEventListener("offline", function() {
$rootScope.$apply(function() {
$rootScope.online = false;
@guptasanchit90
guptasanchit90 / svgIcons.js
Created May 20, 2016 11:13
Directive to load SVG images from withing the code in Angular.js
var app = angular.module('MainApp', ['ngMaterial']);
var icons = {
refresh: "M12 6v3l4-4-4-4v3c-4.42 0-8 3.58-8 8 0 1.57.46 3.03 1.24 4.26L6.7 14.8c-.45-.83-.7-1.79-.7-2.8 0-3.31 2.69-6 6-6zm6.76 1.74L17.3 9.2c.44.84.7 1.79.7 2.8 0 3.31-2.69 6-6 6v-3l-4 4 4 4v-3c4.42 0 8-3.58 8-8 0-1.57-.46-3.03-1.24-4.26z",
share: "M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92 1.61 0 2.92-1.31 2.92-2.92s-1.31-2.92-2.92-2.92z"
};
app.directive('svgIcon', function() {
function link(scope, element, attrs) {
@guptasanchit90
guptasanchit90 / BatteryHelper.java
Created April 8, 2016 07:06
A wrapper class to provide battery information
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import com.mobyta.mobilewebdashboard.ThisApplication;
public class BatteryHelper {
private Intent mBatteryDataIntent;
@guptasanchit90
guptasanchit90 / VoiceGuidedNavigation.java
Created February 2, 2016 12:03
A wrapper class to demonstrate how to implement "http://www.api.ai" in Android. SDK : https://github.com/api-ai/api-ai-android-sdk
import android.content.Context;
import android.os.AsyncTask;
import ai.api.AIConfiguration;
import ai.api.AIDataService;
import ai.api.AIListener;
import ai.api.AIService;
import ai.api.AIServiceException;
import ai.api.model.AIError;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
/**
* Dialog helper class
*/
public class DestructiveDialog {
public DestructiveDialog(Context context, String title, String message, String positive, String negative, final DialogListener dialogListener) {
@guptasanchit90
guptasanchit90 / LocationHelper.java
Created November 22, 2015 09:49
Check location enabled or not
public class LocationHelper{
public static boolean isLocationEnabled(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Check GPS status
boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Check network status
boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
return false;
}
@guptasanchit90
guptasanchit90 / FragmentHelper.java
Created November 22, 2015 09:41
Check if fragment is visible and still not destroyed
public class FragmentHelper {
public static boolean isFragmentVisible(WeakReference<Fragment> fragment) {
if (fragment!=null && fragment.get() != null && fragment.get().getActivity() != null &&
fragment.get()
.isVisible()
&& !fragment.get().isRemoving()) {
return true;
}
return false;
}
package <Package Name>;
import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
public class FontUtils {
/**
* Loads the desired font.
*