Skip to content

Instantly share code, notes, and snippets.

View varunon9's full-sized avatar

Varun kumar varunon9

View GitHub Profile
@varunon9
varunon9 / GalleryModule.java
Created January 8, 2018 17:04
An android native module for react-native. It returns an array of all images from gallery with latest images first (sorting based on DATE_TAKEN).
package com.imagecompressor;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
@varunon9
varunon9 / Category.php
Created January 16, 2018 18:18
Implementing Naive Bayes Classification algorithm into PHP to classify given text as ham or spam. To see complete project visit: https://github.com/varunon9/naive-bayes-classifier
<?php
class Category {
public static $HAM = 'ham';
public static $SPAM = 'spam';
}
?>
@varunon9
varunon9 / app.js
Created May 26, 2018 17:31
app.js file for node.js server using express.
/**
* Created by: Varun kumar
* Date: 23 May, 2018
*/
const express = require('express');
const path = require('path');
//const favicon = require('serve-favicon');
const bodyParser = require('body-parser');
@varunon9
varunon9 / schema.js
Created May 26, 2018 17:36
A simple graphql schema using graphql-tools
/**
* Created by: Varun kumar
* Date: 23 May, 2018
*/
const { makeExecutableSchema } = require('graphql-tools');
const utilityService = require('../services/utilityService');
const userService = require('../services/userService');
@varunon9
varunon9 / graphql-query-client-side.js
Created May 26, 2018 17:41
Querying to graphql server from browser using JQuery Ajax
var globals = {}; // application wide global variable
globals.constants = {
}
globals.showToastMessage = function(heading, message, icon) {
$.toast({
heading: heading,
text: message,
showHideTransition: 'slide',
@varunon9
varunon9 / verify-token.js
Created May 26, 2018 17:52
Security middleware for authentication using jsonwebtoken. This gist demonstrate its usage in graphql-express server
const jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
const env = process.env.NODE_ENV || 'development';
const config = require('../config/config.json')[env];
module.exports = {
verifyToken: function(req, res, next) {
// get token from cookies
@varunon9
varunon9 / user-service.js
Created May 26, 2018 18:00
A service object to interact with MySql database using sequelize module.
const env = process.env.NODE_ENV || 'development';
const config = require('../config/config.json')[env];
const validationService = require('./validationService');
const models = require('../models');
const bcrypt = require('bcrypt');
module.exports = {
@varunon9
varunon9 / CalendarDayComponent.js
Created February 24, 2019 19:41
react-native-toggle-calendar- customized calendar built on top of react-native-calendars to support horizontal and grid calendar view
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import PropTypes from 'prop-types';
const weekDaysNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
class CalendarDayComponent extends React.Component {
constructor(props) {
super(props);
this.onDayPress = this.onDayPress.bind(this);
@varunon9
varunon9 / CalendarDayComponent.js
Created March 19, 2019 17:02
Sample Calendar Day and Header components for react-native-toggle-calendar
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Image } from 'react-native';
import PropTypes from 'prop-types';
const weekDaysNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
class CalendarDayComponent extends React.PureComponent {
constructor(props) {
super(props);
this.onDayPress = this.onDayPress.bind(this);
@varunon9
varunon9 / AlwaysRunningAndroidService.md
Last active April 20, 2024 23:38
How to create an always running service in Android

Full Source Code: https://github.com/varunon9/DynamicWallpaper/tree/always_running_service

Steps-

  1. Create a Foreground Service (MyService.java)
  2. Create a Manifest registered Broadcast Receiver (MyReceiver.java) which will start your Foreground Service
  3. In onDestroy lifecycle of MyService, send a broadcast intent to MyReceiver
  4. Launch the MyService on app start from MainActivity (see step 8)
  5. With above 4 steps, MyService will always get re-started when killed as long as onDestroy of Service gets called
  6. onDestroy method of Service is not always guaranteed to be called and hence it might not get started again