AWS Zertifikat Berechtigungen
icacls "filename.pem" /inheritance:r
icacls "filename.pem" /grant:r Alex:F
VSC Intelliphense errors
C:\Users\Alex\AppData\Roaming\Code\User\settings.json
{
"files.autoSave": "onFocusChange",
"editor.unicodeHighlight.nonBasicASCII": false,
"git.ignoreWindowsGit27Warning": true,
"git.openRepositoryInParentFolders": "never",
"laravel-pint.enable": true,
"editor.formatOnSave": true,
"intelephense.telemetry.enabled": false,
"intelephense.completion.triggerParameterHints": true,
"intelephense.completion.insertUseDeclaration": true,
"intelephense.trace.server": "messages",
"intelephense.diagnostics.undefinedClassConstants": false,
"intelephense.diagnostics.undefinedFunctions": false,
"intelephense.diagnostics.undefinedConstants": false,
"intelephense.diagnostics.undefinedProperties": false,
"intelephense.diagnostics.undefinedTypes": false,
"intelephense.diagnostics.undefinedMethods": false,
}
Update Cert
sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini -d noppal.de -d *.noppal.de
AWS change disk size
- 1. Go to EBS Volumes
- 2. Modify volume
- 3. Check new file size using command: lsblk
- 4. Increase volume of xvda1: sudo growpart /dev/xvda 1
5. sudo xfs_growfs -d /
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html
AWS rc-local
file /etc/rc.local anlegen mit folgendem Inhalt:
#!/bin/sh
# add your commands
# call your scripts here
# ntfy server start
sudo docker run -v /var/cache/ntfy:/var/cache/ntfy -v /etc/ntfy:/etc/ntfy -p 81:80 -itd binwiederhier/ntfy serve --cache-file /var/cache/ntfy/cache.db
# last line must be exit 0
exit 0
sudo systemctl status rc-local
sudo systemctl enable rc-local
sudo systemctl start rc-local
sudo systemctl status rc-local
# it doesn't start because /etc/rc.d/rc.local does not exist
sudo ln -s /etc/rc.local /etc/rc.d/rc.local
sudo systemctl start rc-local
sudo systemctl status rc-local
Google Maps - Lat / Long URL
http://maps.google.com/maps?z=3&t=m&q=loc:13.758347222222+100.49842777778
Stormbreaker
Start SB: sudo python3 st
Start ngrok: ngrok http <port>
Update.php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost:4040/api/tunnels");
// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = json_decode(curl_exec($ch),1);
//print_r($res);
$url=$res['tunnels'][0]['public_url'];
print_r($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://urlaub.noppal.de/store.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"url=".$url);
// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($ch);
curl_close($ch);
print_r($resp);
ngrok http 80 --host-header=urlaub.noppal.de:80
Create Video with FFMPEG
ffmpeg -r 1/5 -start_number 1 -i E:\web\my\tmp\ffmpeg\%04d.JPG -i audio.mp3 -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
Event Handler on dynamic elements
$(document).on('click', 'selector', handler);
Where click is an event name, and handler is an event handler, like reference to a function or anonymous function function() {}
PS: if you know the particular node you're adding dynamic elements to - you could specify it instead of document.
answered Aug 22, 2012 at 1:47
252k7373 gold badges444444 silver badges542542 bronze badges
11
Don't use $(document). The event should be bound to the closest static parent.
Start NTFY on Linux
sudo docker run -v /etc/ntfy:/etc/ntfy -p 81:80 -itd binwiederhier/ntfy serve --cache-file /var/cache/ntfy/cache.db
oder
sudo docker run \
-v /var/cache/ntfy:/var/cache/ntfy \
-v /etc/ntfy:/etc/ntfy \
-p 81:80 \
-itd \
binwiederhier/ntfy \
serve \
--cache-file /var/cache/ntfy/cache.db
PhpUnit - erste Erfahrungen
Hilfreicher Link: https://betterstack.com/community/guides/testing/laravel-unit-testing/#prerequisites
Einzelner Unit Test:
php artisan test --filter {RoomTest}
Alle Tests:
php artisan test
phpunit.xml
Die Files müssen mit “Test.php” enden also z.B RoomTest.php
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
Class Room:
<?php
namespace Tests\Unit;
#use PHPUnit\Framework\TestCase;
use Tests\TestCase;
use App\MyClasses\Room;
class RoomTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function test_the_application_returns_a_successful_response(){
$response = $this->get('/arcade');
$response->assertStatus(200);
}
public function test_room_has()
{
$room = new Room(["Jack", "Peter", "Amy"]); // Create a new room
$this->assertTrue($room->has("Jack")); // Expect true
$this->assertFalse($room->has("Eric")); // Expect false
}
public function test_room_add(){
$room = new Room(["Jack"]); // Create a new room
$this->assertContains("Peter", $room->add("Peter"));
}
public function test_room_remove(){
$room = new Room(["Jack", "Peter"]); // Create a new room
$this->assertCount(1, $room->remove("Peter"));
}
}
TestCase:
<?php
namespace Tests\Unit;
#use PHPUnit\Framework\TestCase;
use Tests\TestCase;
use App\MyClasses\Room;
class RoomTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function test_the_application_returns_a_successful_response(){
$response = $this->get('/arcade');
$response->assertStatus(200);
}
public function test_room_has()
{
$room = new Room(["Jack", "Peter", "Amy"]); // Create a new room
$this->assertTrue($room->has("Jack")); // Expect true
$this->assertFalse($room->has("Eric")); // Expect false
}
public function test_room_add(){
$room = new Room(["Jack"]); // Create a new room
$this->assertContains("Peter", $room->add("Peter"));
}
public function test_room_remove(){
$room = new Room(["Jack", "Peter"]); // Create a new room
$this->assertCount(1, $room->remove("Peter"));
}
}
React is in da house!!
Meine ersten Gehversuche mit React..
Das Ergebis gibts hier: http://friese24.noppal.de/
import React from 'react';
import axios from 'axios';
import { Component } from "react"
import { createRoot } from 'react-dom/client';
import { StrictMode } from "react";
import { useEffect, useState, setState } from "react";
export function Frise() {
const [ inputs, setInputs] = useState({});
const [ friesen, setFriesen ] = useState([]);
const [ friesenpics, setFriesenPics ] = useState({});
const [ actual, setActual ] = useState([]);
const [ plz , setPlz ] = useState('');
const [ form, setForm ] = useState({ plz: '', });
const handleChange = (event) => {
//console.log(event.target.id);
setForm({
...form,
[event.target.id]: event.target.value,
});
};
const ShowFriesenpics = (actual) => {
console.log('Func FriesenPics');
console.log( actual.friesenpics);
/*
const listItems = friesenpics.map((pic) =>
<li>{pic.name}</li>
);
return (
<div>
<ul>{listItems}</ul>
</div>
);
*/
};
const search = (event) => {
event.preventDefault();
let plz = form.plz;
axios.get('getFriesen/' + plz)
.then(function (response) {
let data = response.data.results;
//console.log(data);
//console.log(data.json());
setFriesen(data);
setActual(data[0]);
setFriesenPics(data[0].friesenpics);
//console.log(friesenpics);
//console.log(data[0].friesenpics);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
};
useEffect(() => {
console.log("Show Pics");
console.log(friesenpics);
}, ['friesenpics']);
const showDetails = (friese) => {
//console.log(friese);
setActual(friese);
}
useEffect(() => {
const fetchata = async () => {
const response = await fetch(
'/getFriesen');
const data = await response.json();
setFriesen(data.results);
setActual(data.results[0]);
//console.log("loading Friesenpics:", data.results[0].friesenpics);
//console.log("Frisen updated!");
//console.log("Settinig FPs:" + data.results[0].friesenpics)
}
// Call the function
fetchata();
}, ['friesen']);
return (
<React.StrictMode>
<div className='frise w-full'>
<div className="grid grid-cols-12 gap-4 w-full">
<div className="col-span-12 bg-slate-300">
<div id="search">
<form onSubmit={search}>
<table id="friesenSearchTbl">
<tbody>
<tr><td colSpan="2">Suche </td></tr>
<tr><td className="plz">PLZ </td><td><input type="text" id="plz" name="plz" value={form.plz} onChange={handleChange}></input></td></tr>
<tr><td colSpan="2"><button className='btn'>Search</button></td></tr>
</tbody>
</table>
</form>
</div>
</div>
<div className="col-span-4">
<table className="friesenTable w-full">
<thead>
<tr>
<th>PLZ</th>
<th>NAME</th>
<th>Ort</th>
</tr>
</thead>
<tbody>
{friesen.map(friese =>
<tr key={friese.id} data-item={friese.id} onClick={() => showDetails(friese)}>
<td>{friese.plz}</td>
<td>{friese.name}</td>
<td>{friese.city}</td>
</tr>)}
</tbody>
</table>
</div>
<div className='col-span-8'>
<table>
<tbody>
<tr>
<td className="p-3">Name</td>
<td className="p-3">{actual.name}</td>
</tr>
<tr>
<td className="p-3">Email</td>
<td className="p-3"><a href="{'mailto:'+actual.email}">{actual.email}</a></td>
</tr>
<tr>
<td className="p-3">Adresse</td>
<td className="p-3">{actual.street}</td>
</tr>
<tr>
<td className="p-3">PLZ / Ort</td>
<td className="p-3">{actual.plz} / {actual.city}</td>
</tr>
</tbody>
</table>
<div className="frisenImages">
<img src={"img/friese24/"+ actual.id + "/" + actual.pic}></img>
<ShowFriesenpics actual={actual}></ShowFriesenpics>
</div>
</div>
</div>
</div>
</React.StrictMode>
);
}
if (document.getElementById('reactFrise')) {
const root = createRoot(document.getElementById('reactFrise'));
root.render(
<Frise tab="home" />
);
}
Queues
Queues sind super! Wenn man einen Task hat, der ein bisschen dauert, oder ihn einfach später ausführen möchte.
Dieser Job verschickt Emails, ich benutze den Demo Emailer, den ich schon verwendet habe um Emails ohne Queue zu verschicken.
Wichtig: Der Job muss vom Typ des “Jobs” sein und nicht von dem Typ der verarbeitet werden soll.
$job = new SendEmailJob($details); // nicht DemoEmail
env: (Um den Queue in der DB zu erzeugen, alternativ ginge z.B auch Redis)
QUEUE_CONNECTION=database
Job erzeugen:
php artisan make:job SendEmailJob
Job:
<?php
namespace App\Jobs;
use App\Mail\DemoMail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Mail;
class SendEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $details;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($details)
{
$this->details = $details;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$email = new DemoMail($this->details);
Mail::to($this->details['email'])->send($email);
}
}
Controller:
<?php
namespace App\Http\Controllers;
use App\Jobs\SendEmailJob;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Http\Request;
use App\Mail\DemoMail;
use App\Models\Jobs;
class QueueController extends Controller
{
//use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function index(){
$details['email'] = 'xxx@yyy.de';
$details['title'] = 'My Title';
$details['body'] = 'My Body';
$job = new SendEmailJob($details);
$this->dispatch($job);
echo "Done.";
}
public function showJobs(){
$jobs = Jobs::all();
return view('queue.jobs', compact('jobs'));
}
}
Und den Worker starten, der die Jobs verarbeitet:
php artisan queue:work
WhatsApp Nachrichten
Heute habe ich mich einmal mit WhatsApp beschäftigt.
Das geht wohl nicht native, daher braucht man einen Provider, ich habe Twilio genommen.
composer require twilio/sdk
Und der Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Twilio\Rest\Client;
class TwilioController extends Controller
{
public function sendWhatsApp( $to, $body )
{
$sid = env('TWILIO_AUTH_SID');
$token = env('TWILIO_AUTH_TOKEN');
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("whatsapp:" .$to, // to
array(
"from" => "whatsapp:+xxxxxxxxxxxx",
"body" => $body
)
);
//print($message->sid);
}
}
Facebook Login
Anmeldung via Facebook. Hat länger gedauert, als es sollte.. Aber letztendlich funktioniert es jetzt.
Der Weg war:
composer require laravel/socialite
und das stateless() im Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
use Exception;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
class FacebookController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function redirectToFacebook()
{
return Socialite::driver('facebook')->redirect();
}
/**
* Create a new controller instance.
*
* @return void
*/
public function handleFacebookCallback()
{
try {
$user = Socialite::driver('facebook')->stateless()->user();
$finduser = User::where('facebook_id', $user->id)
->orWhere('email', $user->email)
->first();
if($finduser){
$res = Auth::login($finduser);
return redirect()->intended('blog');
}else{
$newUser = User::updateOrCreate(['email' => $user->email],[
'name' => $user->name,
'facebook_id'=> $user->id,
#'password' => encrypt('123456dummy')
]);
Auth::login($newUser);
return redirect()->intended('dashboard');
}
} catch (Exception $e) {
dd($e->getMessage());
}
}
}
Post als Gast
Gast Test..
Rich Text Test:
Bold
Italic
Code:
<form id='frmtmp' action='{{route("blog.makeComment")}}' method='POST'>
@csrf
<input type="hidden" name="user_id" value="{{ $user_id }}">
<input type="hidden" name="blog_id" value="{{ $id }}">
<textarea name='comment' id="blog-content"></textarea>
<button class="blog-btn-add-comment" type='button' onclick="saveComment()">Comment</button>
</form>
File Upload with progress bar
Ja das Tutorial kann man in wenigen Minuten nachbauen.
Nächster Step wäre wohl, das in einen Trait zu packen. https://www.positronx.io/laravel-jquery-ajax-file-upload-progress-bar-tutorial/
Mit der entsprechenden Hilfe von itsolutionstuff.com klappt jetzt auch der Email Versand mit Laravel!
php artisan make:mail DemoMail
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class DemoMail extends Mailable
{
use Queueable, SerializesModels;
public $mailData;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($mailData)
{
$this->mailData = $mailData;
}
public function __invoke()
{
return $this;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject($this->mailData['title'])
->view('email.demoMail');
}
}
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
use App\Mail\DemoMail;
class MailController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index($mailData=[])
{
if (!isset($mailData['title']) || $mailData['title']=="") {
$mailData['title'] = "Test";
}
if (!isset($mailData['body']) || $mailData['body']=="") {
$mailData['body'] = "This is for testing email using smtp.";
}
Mail::to('xxx@yyy.de')->send(new DemoMail($mailData));
}
}
Comments
Die Kommentare werden über ein Ajax Request erstellt bzw. gelöscht.
Tailwind
Laravel Component
Die einzelnen Blog Einträge werden jetzt als Component gerendert.
Je mehr ich mich in Laravel einarbeite, desto mehr merke ich wie viel ich noch nicht weiß....
Laravel Start!
Willkommen zu meinem ersten Post ! Sinn der Sache ist, sich ein bisschen in Laravel einzuarbeiten und das Framework kennenzulenen. Das erste Laravel Projekt ist an den Start gebracht und das erste CRUD Tutorial habe ich erfolgreich beendet. Ich fange hier einmal an mit einem kleinen Blog - wir werden sehen wohin mich die Reise mit Laravel führt. Laravel Version: 9.39.0 vite Jetstream Tailwind