Skip to content

Instantly share code, notes, and snippets.

View kamaroly's full-sized avatar

Kamaro Lambert kamaroly

View GitHub Profile
@michaelwa
michaelwa / organization.ex
Last active July 29, 2024 05:08
Elixir Organization for multitenant
defmodule MyAshPhoenixApp.Client.Organization do
use Ash.Resource,
domain: MyAshPhoenixApp.Client,
data_layer: AshPostgres.DataLayer
defimpl Ash.ToTenant do
# %{:domain => _, :id => _, _ => _}
# def to_tenant(resource, %MyAshPhoenixApp.Client.Organization{id: id}) do ## ----->>>>> this line causes a compilation error
def to_tenant(resource, %{:domain => domain, :id => id}) do ## ---->>>> this line creates a warning
if Ash.Resource.Info.data_layer(resource) == AshPostgres.DataLayer
@grumpysi
grumpysi / gist:265a420507f1f54e3e8a457db88ca637
Created September 24, 2019 09:13
Generate new ssh Laravel Forge deploy key
ssh-keygen -f /home/forge/.ssh/id_rsa -t rsa -N ''
@abarke
abarke / docx_editor.php
Last active September 2, 2024 11:13 — forked from AndrewChamp/docx_editor.php
Edit a Microsoft Word .docx file using PHP and the zip extension.
<?php
$input = 'original.docx';
$output = 'modified.docx';
$replacements = [
'{test-placeholder-1}' => 'test successful 1',
'{test-placeholder-2}' => 'test successful 2',
'{test-placeholder-3}' => 'test successful 3',
'{test-placeholder-4}' => 'test successful 4',
];
@IftekherSunny
IftekherSunny / SubscribersTest.php
Last active February 2, 2022 11:29
Laravel File Upload API Test
<?php
use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class SubscribersTest extends TestCase
{
use DatabaseMigrations, WithoutMiddleware;
@juampynr
juampynr / guzzle_post.php
Last active May 1, 2023 19:52
Sample POST request with Guzzle
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'http://example.com',
]);

UsedByTeams Model Trait For Laravel Spark

Automatically limit your models to the current team

So you're using spark, and you have teams enabled. You start creating models and want to have them be team specific. Instead of writing, Model::where('team_id', auth()->user()->currentTeam->id)->get(); use this trait to add that behind the scenes so that every time you call on your model, it's assumed that you mean for the current team.

This assumes that the model has a team_id, while it adds a scope of where team_id = currentTeam->id.

Note: Implicit Route Model Binding in 5.2, auth session doesn't exist at the point of this trait causing issue. fixed in 5.3

@rtconner
rtconner / SftpServiceProvider.php
Last active June 27, 2024 09:07
Provider so you can add a 'sftp' connection in Laravel 5 filesystems.php - "Call to undefined method League\Flysystem\Filesystem::createSftpDriver"
<?php
namespace App\Providers;
use League\Flysystem\Sftp\SftpAdapter;
use Storage;
use League\Flysystem\Filesystem;
use Illuminate\Support\ServiceProvider;
/**
@kamaroly
kamaroly / form.html
Last active August 29, 2015 14:20 — forked from gosseti/form.html
<form accept-charset="UTF-8" action="/payment" class="cardInfo" method="post">
<fieldset class="cardInfo__cardDetails">
<div class="form-row cardInfo__cc-num">
<label for="cc-num"><abbr title="required">*</abbr><span>Card Number</span></label>
<div class="cc-num__wrap">
<!-- using type="tel" because type="number" doesn’t pass HTML5 form validation with jQuery.payment formatting -->
<input id="cc-num" type="tel" class="paymentInput cc-num" placeholder="•••• •••• •••• ••••" autocompletetype="cc-number" required="required">
<span class="card" aria-hidden="true"></span>
@rkellermeyer
rkellermeyer / richards_crud.erl
Created November 12, 2014 19:32
Erlang Crud
-module(richards_crud).
-compile(export_all).
new() ->
maps:new().
build(Key, Value, Map) ->
maps:put(Key, Value, Map).
@tahirm
tahirm / mysqldump.sql
Created March 27, 2014 13:44
mysqldump command to dump a remote database in locally. #db #sql #mysql #mysqldump #remote
mysqldump -u USER -p -h dev.incuray.com DATABASE > /path/to/output/file/DATABASE.sql;