Skip to content

Instantly share code, notes, and snippets.

View paulobunga's full-sized avatar
🏠
Available for work

Paul Obunga paulobunga

🏠
Available for work
View GitHub Profile
@paulobunga
paulobunga / DeviceInformation.java
Created July 13, 2019 06:18 — forked from hendrawd/DeviceInformation.java
Helper class for getting Device Information
package your.app.util;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
@paulobunga
paulobunga / ImageInputHelper.java
Created July 4, 2019 01:43 — forked from eluleci/ImageInputHelper.java
Android: Helper for Android for selecting image from gallery, taking a photo with camera and cropping image.
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.util.Log;
import java.io.File;
import java.io.IOException;
@paulobunga
paulobunga / LocationFragment.java
Created June 28, 2019 14:32 — forked from louisbl/LocationFragment.java
Fragment for Location Manager
package;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
@paulobunga
paulobunga / script.sh
Created June 14, 2019 14:30
Enable FTP Access for wordpress plugin install
chown -R www-data:www-data /var/www
find /var/www/ -type d -exec chmod 755 {} \;
find /var/www/ -type f -exec chmod 644 {} \;
@paulobunga
paulobunga / user_table.sql
Created June 10, 2019 16:41
Create users table using the sql below
CREATE TABLE users(
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`firstname` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL);
@paulobunga
paulobunga / insert_unique_data_from_other_table.md
Created June 2, 2019 14:57
MySQL Trigger to insert distinct values while checking existing in new table

INSERT INTO locations(dhis_id, facility_name, location) SELECT DISTINCT dhis_id, facility_name, location FROM dhis_count WHERE dhis_id NOT IN(SELECT dhis_id FROM locations)

@paulobunga
paulobunga / mysql_find_duplicates.md
Created June 2, 2019 13:50
MySQL Find duplicate entries and delete them

SELECT location, COUNT(location) FROM locations GROUP BY location HAVING COUNT(location) > 1

@paulobunga
paulobunga / create_working_directory.md
Last active February 12, 2019 21:37
codeigniter_ajax_crud

Creating a working directory / project folder

  • Open terminal
  • cd ~
  • cd Desktop
  • cd PROJECTS
  • mkdir codeigniter_ajax_crud
@paulobunga
paulobunga / auth-middleware.js
Last active January 28, 2019 13:18
Auth middleware, checks if user is logged in or not
const jwt = require('jsonwebtoken');
exports.isAuthenticated = (req, res, next) => {
//Get the request headers and check if we have an authorization header with our token
if (req.headers && req.headers.authorization && req.headers.authorization.split(' ')[0] === 'JWT') {
//Check the token for validity
var token = req.headers.authorization.split(' ')[1];
jwt.verify(token, 'our-jwt-secret-goes-here', (err, payload) => {
const express = require('express');
const router = express.Router();
const authMiddleware = require('../middleware/auth-middleware');
const userController = require('../controllers/user-controller');
//Get a list of all the users
//We are using the authentication middleware to protect this route from unauthorised access
router.get('/', authMiddleware.isAuthenticated, userController.getUsers);