Skip to content

Instantly share code, notes, and snippets.

View kamaroly's full-sized avatar

Kamaro Lambert kamaroly

View GitHub Profile
@kamaroly
kamaroly / CreateTransporterAPITest.py
Created December 6, 2022 10:26
Django Rest Framework External API Mock. You must install requests_mock using pip like `pip install requests_mock`
# In your test classes. For example OnboardTransporterAPITest.py
=================================================================
import requests_mock
from rest_framework import status
from django.urls import include, path, reverse
from rest_framework.test import APITestCase, URLPatternsTestCase
@requests_mock.Mocker()
class OnboardTransporterAPITest(APITestCase, URLPatternsTestCase):
@kamaroly
kamaroly / eloquentRawConditions.php
Last active August 12, 2020 22:37
These two methods are helpers to be added in eloquent when you want to only extract raw query conditions
<?php
namespace App;
use Illuminate\Database\Eloquent\Model as EloquentModel;
class Model extends EloquentModel
{
@kamaroly
kamaroly / sortTable.js
Last active July 27, 2020 08:05
A very simple light weight Vanilla Javascript HTML Table sorter
/**
* Sort an HTML TABLE IN DOM element
* @usage 1) add #sortable-table-input id to your input and listen to onkeyup event
Example: <input id="sortable-table-input" onkeyup="sortTable()" />
2) Add #sortable-table id to your HTML table
* @return
*/
function sortTable() {
// Declare variables
var input, filter, table, tableRow, index, rowTextValue;
@kamaroly
kamaroly / single-table-permission-mysql.sql
Created July 10, 2020 06:30
Setting single table permission in mysql
GRANT SELECT ON ceb.loans TO user@'%';
FLUSH PRIVILEGES;
@kamaroly
kamaroly / GoogleSheetMySqlConnection.js
Last active December 1, 2023 01:39
This Gits help you connect to your MySql Database from google sheet, Make surey ou whitelist google IPs ( see the list here https://developers.google.com/apps-script/guides/jdbc#creating_other_database_connections) then go to Tools > Scripts Editor
var server = "Your DATABASE HOST";
var databaseName = "DATABASE NAME";
var username = "password";
var password = "Username";
var port = 3306;
/**
* Open network to Database
*/
function openConnection() {
@kamaroly
kamaroly / EloquentRoutePaths.php
Last active June 23, 2020 06:47
This trait adds path to your eloquent model ( $article->edit_path, $article->show_path, $article->update_path,$article->destroy_path).
<?php
use Exception;
trait EloquentRoutePaths {
/**
* Actions that are allowed to be performed on this
* Model
* @var array
*/
@kamaroly
kamaroly / EloquentRoutePaths.php
Created January 27, 2020 07:04
This trait adds path to your eloquent model ( $article->edit_path, $article->show_path, $article->update_path,$article->destroy_path)
use Exception;
trait EloquentRoutePaths {
/**
* Actions that are allowed to be performed on this
* Model
* @var array
*/
protected $actions = ['show','edit','update','destroy'];
@kamaroly
kamaroly / elegant-dashboard-with-chartjs.html
Created August 22, 2019 18:14
This script is configured to make your chartjs line chart looks elegant.
<div class="card col-md-8">
<div class="cart-header">
<span class="card-title">Today </span>
<span class="dot dot-red"></span> Line red: <span class="text-red-600"> 0 RWF</span>
<span class="dot dot-yellow"></span> Line green: <span class="text-yellow-600"> 0 RWF </span>
</div>
<div class="card-body">
<canvas id="transactionsChart" ></canvas>
@kamaroly
kamaroly / phpunit.xml
Last active May 27, 2019 11:26
WordPress plugin phpunit.xml for easy unit testing in WordPress plugin development. Put your tests in `tests` folder in your plugins
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../../../wp-load.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
@kamaroly
kamaroly / Extract numbers from Text or String
Created April 30, 2019 10:31
This is an excel formula helps you extract numbers only from text. Replace E2 with cell that has text mixed with number For a text like "We have 17 students" it will return 17
=SUMPRODUCT(MID(0&E2, LARGE(INDEX(ISNUMBER(--MID(E2, ROW(INDIRECT("1:"&LEN(E2))), 1)) * ROW(INDIRECT("1:"&LEN(E2))), 0), ROW(INDIRECT("1:"&LEN(E2))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(E2)))/10),