Skip to content

Instantly share code, notes, and snippets.

@ptheofan
ptheofan / docker-compose.yml
Last active January 24, 2024 00:12
Typesense + Mongodb
version: "3.8"
volumes:
imdb-mongodb-primary: {}
imdb-mongodb-secondary: {}
imdb-mongodb-arbiter: {}
services:
mongodb-primary:
image: mongo:latest
@ptheofan
ptheofan / copilot-fun.md
Created March 21, 2023 12:18
copilot-infinite-loop

Having fun with copilot... all I had was a class Token with a handful of properties and then with every new line it went from withoutX to withoutXandXandX.... enjoy... no idea if it would ever really run out of suggesstions there.

get payloadWithoutNulls(): any {
    const payload = this.payload;
    Object.keys(payload).forEach(key => payload[key] == null && delete payload[key]);
    return payload;
  }
  
@ptheofan
ptheofan / latestOnly.js
Last active February 16, 2022 14:39
Run only the latest promise. Will cancel all the previous ones. Similar to AbortController which couldn't get to work with Axios. This one works.
// Couldn't get the AbortController to work with Axios post so real quick and dirty, similar solution.
// This does NOT abort the request, it just rejects the concurrently previously running promises.
// Can make it abort also though no need to if AbortController works for you.
//
// How to use
// Just wrap your axios call (or any promise in it).
// first parameter is a uid (use some convenient name)
// latestOnly('mySearchCall', ....)
// if you call latestOnly('mySearchCall') before the promise has resolved the previous (still running) promise will
// return error "AbortError"
@ptheofan
ptheofan / nginx.conf
Created February 3, 2022 21:15 — forked from mreschke/nginx.conf
Nginx config for multiple laravel sites based on /api/v1 url paths
# This config will host your main [Laravel] GUI application at /, and any additional [Lumen] webservices at /api/v1 and /api/v2...
# This also works perfectly for all static file content in all projects
# This is full of debug comments so you can see how to print debug output to browser! Took me hours to nail this perfect config.
# Example:
# http://example.com - Main Laravel site as usual
# http://example.com/about - Main Laravel site about page as usual
# http://example.com/robots.txt - Main Laravel site static content as usual
# http://example.com/api/v1 - Lumen v1 api default / route
# http://example.com/api/v1/ - Lumen v1 api default / route
@ptheofan
ptheofan / Color.js
Created January 14, 2022 17:42
Color Handling Class (v0.0.1)
export class Color {
/** @type {number} range 0 to 1 */
#r = 0.0;
/** @type {number} range 0 to 1 */
#g = 0.0;
/** @type {number} range 0 to 1 */
#b = 0.0;
/** @type {number} range 0 to 1 */
#h = 0.0;
/** @type {number} range 0 to 1 */
@ptheofan
ptheofan / NestedSetToArrayExample.php
Last active August 22, 2021 08:58
Yii2 NestedSets class trait as a nice helper to use with any class that uses the NestedSets behavior
<?php
/**
* NestedSets in SQL - How to export a nested set subtree or tree into Yii2 Menu widget and as
* JsTree valid DataSet (nested format).
*/
class Category extends \yii\db\ActiveRecord
{
/**
* @return array
*/
1. First go to the console, click the volume, actions and grow it.
2. ssh to the machine
```bash
> lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 89.1M 1 loop /snap/core/8039
loop1 7:1 0 18M 1 loop /snap/amazon-ssm-agent/1480
loop2 7:2 0 89.1M 1 loop /snap/core/8213
nvme0n1 259:0 0 40G 0 disk
<?php
[
'dsn' => 'mongodb://username:password@objectdb.cluster-xxx.eu-central-1.docdb.amazonaws.com:27017/database_name',
'options' => [
'ssl' => true,
'tlsAllowInvalidCertificates' => true,
'tlsAllowInvalidHostnames' => true,
'tlsCAFile' => '/apps/certificates/rds-combined-ca-bundle.pem',
],
]
@ptheofan
ptheofan / cloudflare_https_prefix.php
Created March 21, 2017 21:05
Cloudflare flexible SSL - trick PHP scripts to identify HTTPS when cloudflare reports it was HTTPS request
<?php
/*
Instructions
Go to your php.ini for the web scripts (pointless for cli scripts)
Make the following adjustment
auto_prepend_file = full/path/to/clousflare_https_prefix.php
reload/restart php service (or apache if running via apache)
How this works
local ret_status="$FG[255]$BG[$THEME_HOST_BG] %m %{$reset_color%} %(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
RPROMPT="[ %D{%H:%M} ]"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"