Skip to content

Instantly share code, notes, and snippets.

View kamaroly's full-sized avatar

Kamaro Lambert kamaroly

View GitHub Profile
@kamaroly
kamaroly / can.ex
Created October 6, 2024 09:37
How To Use Ash framework in Phoenix with user permission example
defmodule MyApp.Accounts.Checks.Can do
use Ash.Policy.SimpleCheck
def describe(_opts) do
"Check if a user/ actor has permission on a specific resource"
end
# @impl true
def match?(nil, _, _), do: false
@kamaroly
kamaroly / Caddyfile
Created November 22, 2024 21:01
I use these batch script to achieve Zero-deployment for phoenix application with releases without docker.
your-domain.com {
reverse_proxy localhost:4010 localhost:4020 localhost:4030 localhost:4040 localhost:4050 localhost:4060
}
@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'];