Skip to content

Instantly share code, notes, and snippets.

View gander's full-sized avatar
🏠
It’s Not a Bug, It’s a Feature.

Adam Gąsowski gander

🏠
It’s Not a Bug, It’s a Feature.
  • Warsaw, Poland
  • 22:54 (UTC +01:00)
View GitHub Profile
const API_URL = "https://api.openai.com/v1/chat/completions";
const MAX_TOKENS = 1500;
const TEMPERATURE = 0.5;
const SYSTEM_PROMPT = 'Act as assistant';
const MESSAGES = ["hello", "hi!", "how are you?"];
async function openAICompletion(msg) {
const options = {
method: "POST",
headers: {
@timfish
timfish / README.md
Last active October 21, 2024 05:02
Sentry Cloudflare Workers Proxy - Makes JavaScript and event submission first-party!
  • Add the worker.js code to a new Cloudflare Worker
  • Set up a worker for your domain than responds to /tunnel/* and point it to your new worker
  • Add the Sentry script to your html but replace https://browser.sentry-cdn.com/ with ./tunnel/
    • Eg. <script src="./tunnel/6.9.0/bundle.min.js"></script>
  • init Sentry with the tunnel option set to /tunnel/
    • Eg. Sentry.init({ dsn: "__DSN__", tunnel: "/tunnel/" })
  • Rejoice at how everything now works with ad blockers
@M-Porter
M-Porter / vue3-webpack.config.js
Last active January 22, 2023 02:08
Vue3 Webpack Config
const path = require('path');
const webpack = require('webpack');
const VueLoaderPlugin = require('vue-loader/dist/plugin').default;
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const isProd = process.env.NODE_ENV === 'production';
const resolvePath = (...args) => path.resolve(path.join(__dirname, ...args));
@gander
gander / TerribleDateFixer.php
Last active December 3, 2020 11:59
Scary code showing how not to code. Found in production
<?php
class DateFixer {
public function fix(string $date): string {
$time = new DateTime($date);
$time->modify('+3 days');
return $time->format('Y-m-d');
}
}
@eduardo-matos
eduardo-matos / rabbit-graceful-shutdown.js
Last active July 8, 2024 15:40
RabbitMQ graceful shutdown in NodeJS
const amqp = require('amqplib');
const uuid = require('uuid')
const CONSUMER_TAG = uuid.v4();
const QUEUE_NAME = 'my_queue'
async function main() {
const conn = await amqp.connect('amqp://guest:guest@localhost:5672/%2F');
const channel = await conn.createChannel();
await channel.assertQueue(QUEUE_NAME);

How to setup a practically free CDN using Backblaze B2 and Cloudflare

⚠️ Note 2023-01-21
Some things have changed since I originally wrote this in 2016. I have updated a few minor details, and the advice is still broadly the same, but there are some new Cloudflare features you can (and should) take advantage of. In particular, pay attention to Trevor Stevens' comment here from 22 January 2022, and Matt Stenson's useful caching advice. In addition, Backblaze, with whom Cloudflare are a Bandwidth Alliance partner, have published their own guide detailing how to use Cloudflare's Web Workers to cache content from B2 private buckets. That is worth reading,

@andyrbell
andyrbell / luks_backup.txt
Created March 10, 2019 14:35
clonezilla luks backup
backup luks partition
1. Boot clonezilla
2. Drop into the command line
3. open the encrypted external drive partition
cryptsetup luksOpen /dev/sda3 backup
@winguse
winguse / Tenda U9 on linux.md
Last active October 20, 2023 09:40
Tenda U9 on linux

Two files:

  • /etc/usb_modeswitch.d/rtl8821cu
  • /usr/share/usb_modeswitch/0bda:1a2b
TargetVendor=0x0bda
TargetProduct=0x1a2b
StandardEject=1
@ubergesundheit
ubergesundheit / readme.md
Last active November 14, 2024 20:56
systemd traefik.service

systemd Service Unit for Traefik

Adapted from caddy systemd Service Unit

The provided file should work with systemd version 219 or later. It might work with earlier versions. The easiest way to check your systemd version is to run systemctl --version.

Instructions

We will assume the following:

@dobesv
dobesv / dev_signed_cert.sh
Last active October 14, 2024 08:30
Script to create (1) a local certificate authority, (2) a host certificate signed by that authority for the hostname of your choice
#!/usr/bin/env bash
#
# Usage: dev_signed_cert.sh HOSTNAME
#
# Creates a CA cert and then generates an SSL certificate signed by that CA for the
# given hostname.
#
# After running this, add the generated dev_cert_ca.cert.pem to the trusted root
# authorities in your browser / client system.
#