Skip to content

Instantly share code, notes, and snippets.

View kamaroly's full-sized avatar

Kamaro Lambert kamaroly

View GitHub Profile
@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 / WooCommerce Auto update cart after quantity change.php
Last active October 12, 2023 16:57
Auto update cart after quantity change. You trigger the click, but the button doesn't have enough time to become enabled, so that is why, by the time you click the second time the button becomes enabled. Remove the "disabled" propriety before triggering the click. This should be added in **footer.php** of your child theme
<?php if (is_cart()) { ?>
<script type="text/javascript">
// Each time quantity in the cart changes, trigger update
// cart option
jQuery('div.woocommerce').on('change', '.qty', function(){
// Make sure the button is enabled before triggering the event
// otherwise this won't work.
jQuery("[name='update_cart']").prop("disabled", false);
jQuery("[name='update_cart']").trigger("click");
});
@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 / 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">