Skip to content

Instantly share code, notes, and snippets.

@timlrx
timlrx / install-caddy.sh
Created June 10, 2024 02:29
Shell script to install caddy
#!/bin/bash
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
# Create a Caddyfile for reverse proxy
sudo tee /etc/caddy/Caddyfile > /dev/null <<EOF
@timlrx
timlrx / log.py
Created November 21, 2023 13:22
Pretty Python Logging
import logging
from rich.logging import RichHandler
logging.basicConfig(
level=logging.DEBUG,
format="%(message)s",
datefmt="[%X]",
handlers=[RichHandler(rich_tracebacks=True, omit_repeated_times=False)],
)
@timlrx
timlrx / extract-url-from-sitemap.js
Created April 21, 2023 02:52
Extract url from sitemap from browser console
// Extract the URLs from the sitemap on the current page
const urls = Array.from(document.getElementsByTagName("url")).map(url => url.getElementsByTagName("loc")[0].textContent.trim());
// Function to convert an array to a CSV string
function arrayToCSV(arr) {
return arr.map(row => row.join(",")).join("\n");
}
// Convert the URLs to a CSV string and log it to the console
const csv = arrayToCSV([["URL"], ...urls.map(url => [url])]);
@timlrx
timlrx / startup.sh
Created March 22, 2023 09:28
Shell script to install python (via pyenv), node (via nvm) and docker
#! /bin/bash
sudo apt-get update -y
# Basic packages
sudo apt-get install -y \
git \
apt-transport-https \
ca-certificates \
curl \
gnupg \
@timlrx
timlrx / toMotifFormat.js
Created April 22, 2021 09:34
neo4j to motif format
import Record from 'neo4j-driver/types/record';
export const buildNode = (n: any) => {
let node: Node = {
id: `node-${n.identity.toString()}`,
labels: n.labels[0],
};
if (n.properties) {
for (let [key, value] of Object.entries(n.properties)) {
node[key] = value instanceof Neo4j.types.Integer ? value.toInt() : value;
@timlrx
timlrx / ExecuteQuery.js
Last active April 22, 2021 09:32
Execute query component neo4j hooks
import { Neo4jContext, Neo4jProvider, useDatabases } from 'use-neo4j';
const ExecuteQuery = ({
driver,
nextStep
}) => {
return (
<Neo4jProvider driver={driver}>
<CypherQuery
nextStep={nextStep}
@timlrx
timlrx / ConnectDatabase.js
Last active April 22, 2021 09:07
Connect Neo4j Database
import { createDriver } from 'use-neo4j';
const DEFAULT_DB_SETTINGS = {
neo4jHost: 'localhost',
neo4jPort: '7687',
neo4jUsername: '',
neo4jPassword: '',
};
const ConnectDatabase = ({ driver, setDriver, nextStep }) => {
@timlrx
timlrx / neo4j-motif-connector.js
Created April 22, 2021 08:51
Neo4j Motif Pseudocode
const [driver, setDriver] = useState();
return (
<ProgressStepper currentStep={currentStep}>
{currentStep === 1 && (
<ConnectDatabase
driver={driver}
setDriver={setDriver}
nextStep={nextStep}
/>