Skip to content

Instantly share code, notes, and snippets.

View walteranyika's full-sized avatar

elCoder walteranyika

View GitHub Profile
@walteranyika
walteranyika / settings.py
Created November 17, 2023 12:10
logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {process:d} {message}',
'style': '{',
},
},
'handlers': {
@walteranyika
walteranyika / mpesa.py
Last active November 17, 2023 11:05
Quick Utility File To Handle STK Puush Mpesa
import json
from base64 import b64encode
from datetime import datetime
import requests
from requests.auth import HTTPBasicAuth
def get_access_token():
@walteranyika
walteranyika / navbar.html
Last active November 10, 2023 05:07
Navigation for paginated results
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
{% if employees.has_previous %}
<li class="page-item">
<a class="page-link" href='?page={{ employees.previous_page_number }}'>Previous</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href='' tabindex="-1" aria-disabled="True">Previous</a>
</li>
@walteranyika
walteranyika / gist:956d53fa60ed993d0b88bab9c01548ef
Created November 2, 2023 09:51 — forked from gameame/gist:1376105
Enforce unique upload file names in Django
def unique_filename(path):
"""
Enforce unique upload file names.
Usage:
class MyModel(models.Model):
file = ImageField(upload_to=unique_filename("path/to/upload/dir"))
"""
import os, base64, datetime
@walteranyika
walteranyika / JetbrainsEvaluationReset_2020.py
Created February 16, 2021 04:19 — forked from mreyesv/JetbrainsEvaluationReset_2020.py
[Activate] A Python Script To Reset The Evaluation License Of These Jetbrains Products Released In 2020 Or Later (IntelliJIdea, CLion, Rider, PyCharm, RubyMine, GoLand )
# Reset Jetbrains 2020 Products
import glob
import os
import winreg
from os import path
from os.path import expanduser
home = expanduser("~")
newJetbrainsHome = path.join(home, "AppData\Roaming\JetBrains")
@walteranyika
walteranyika / intellij-trial-reset.sh
Created April 1, 2020 16:45 — forked from beci/intellij-trial-reset.sh
reset intellij idea 14 - 2018.x.x evaluation
#!/bin/bash
# Thanks @ketos @krishjun @denis111
## declare array of tools
declare -a tools=(
"DataGrip"
"CLion"
"Rider"
"PhpStorm"
@walteranyika
walteranyika / Updates.java
Last active January 22, 2023 04:43
The check for updates function used to do in app updates from google play store
//Add this to gradle
// implementation 'com.google.android.play:core:1.5.0'
private static final int MY_REQUEST_CODE = 2399;
private void checkForUpdates() {
final AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
@walteranyika
walteranyika / SignInActivity.java
Created April 5, 2019 14:18
Login with facebook gist
package io.walter.foodtaskerapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
//bit.ly/2WIKPgz
double latitude = 0.0;
double longitude = 0.0;
private FusedLocationProviderClient fusedLocationClient;
// fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
public void fetchGPS() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;