Skip to content

Instantly share code, notes, and snippets.

@heartshare
heartshare / HandleInertiaRequests.php
Created July 28, 2023 07:33 — forked from lukaskleinschmidt/HandleInertiaRequests.php
inertia-laravel multiple root views
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Inertia\Middleware;
class HandleInertiaRequests extends Middleware
{
# Not a production ready deployment solution.
# Shell commands to enable docker swarm on multiple Ubuntu nodes.
# Use these commands for reference.
# Copy ssh public key to all nodes
# Will ask for root password, once the ssh successful root ssh public key will be added to docker manager node
for host in host1 host2 host3 host4
do
ssh-copy-id root@${host}
done

Introduction

A software development that plans development how developer coding and testing that process is a continuous integration and then continuous delivery is a process that auto testing on staging[docker] that will marge other code committed by other developers and then deploy to production server manually OR continuous deployment is a process that auto testing and auto-deploy to a production server, aim to automatic DevOps.

How CI/CD works

every time you do git push will trigger CI operation that will follow the user script instruction (gitlab-ci.yml) to do DevOps operation.

create a git project

@heartshare
heartshare / cloudflare.sh
Created June 8, 2023 08:23 — forked from Manouchehri/cloudflare.sh
Allow CloudFlare only
# Source:
# https://www.cloudflare.com/ips
# https://support.cloudflare.com/hc/en-us/articles/200169166-How-do-I-whitelist-CloudFlare-s-IP-addresses-in-iptables-
for i in `curl https://www.cloudflare.com/ips-v4`; do iptables -I INPUT -p tcp -m multiport --dports http,https -s $i -j ACCEPT; done
for i in `curl https://www.cloudflare.com/ips-v6`; do ip6tables -I INPUT -p tcp -m multiport --dports http,https -s $i -j ACCEPT; done
# Avoid racking up billing/attacks
# WARNING: If you get attacked and CloudFlare drops you, your site(s) will be unreachable.
iptables -A INPUT -p tcp -m multiport --dports http,https -j DROP
# Static Brotli:
# Browser accepts brotli, and matching pre-compressed file exists => rewrite to .br file
# For each file format set the correct mime type (otherwise brotli mime type is returned) and prevent Nginx for recompressing the files
set $extension "";
if ($http_accept_encoding ~ br) {
set $extension .br;
}
if (-f $request_filename$extension) {
rewrite (.*) $1$extension break;
@heartshare
heartshare / php-return-redis-handle-into-redis-pool.php
Created May 31, 2023 01:16 — forked from linuxd3v/php-return-redis-handle-into-redis-pool.php
PHP Swoole - properly returning the pooled redis handle into the pool in a "finally" block
protected function removeSomeListItemBlahBlah(string $name, string $key)
{
try {
$cacheHandle = $this->pool->borrow();
$result = $cacheHandle->lrem($name, $key, 0);
} catch (Throwable $e) {
// Log the error
$this->logger->error('Exception while trying to removeSomeListItemBlahBlah', ['exception' => $e]);
import SwiftUI
struct ContentView: View {
@StateObject var service = ChatGPTService()
@State var textResponse = ""
var body: some View {
VStack {
Text("Bot says: \(textResponse)")
Button {
Task {
@heartshare
heartshare / nginx-wordpress.conf
Created February 21, 2023 01:12 — forked from nfsarmento/nginx-wordpress.conf
Harden wordpress security nginx
############ WordPress ####################
# Disable logging for favicon and robots.txt
location = /favicon.ico {
try_files /favicon.ico @empty;
access_log off;
log_not_found off;
expires max;
}
@heartshare
heartshare / README.md
Created February 14, 2023 08:24 — forked from djfdyuruiry/README.md
WSL 2 - Enabling systemd

Enable systemd in WSL 2

NOTE: If you have Windows 11 there is now an official way to do this in WSL 2, use it if possible - see MS post here (WINDOWS 11 ONLY)

This guide will enable systemd to run as normal under WSL 2. This will enable services like microk8s, docker and many more to just work during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.

  • To enable systemd under WSL we require a tool called systemd-genie

  • Copy the contents of install-sg.sh to a new file /tmp/install-sg.sh: