Skip to content

Instantly share code, notes, and snippets.

Prompt Engineering

Автор: Lee Boonstra

Благодарности

Содержание предоставили:

  • Michael Sherman
  • Yuan Cao
@valmat
valmat / LockedKv.cpp
Created July 4, 2024 20:30
LockedKv is a thread safe wrapper on a KV storage
#pragma once
#include <mutex>
#include <utility>
#include <type_traits>
namespace details {
template <typename T, typename = void>
struct has_del_method : std::false_type {};
@valmat
valmat / safe_amqpcpp.h
Created April 9, 2024 20:06
Suppress warnings for a library (example)
#pragma once
// Suppress warnings for AMQP-CPP
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wclass-conversion"
#pragma clang diagnostic ignored "-Wdeprecated-copy"
#include <amqpcpp.h>
#include <amqpcpp/libev.h>
@valmat
valmat / gitaitag.sh
Last active December 11, 2024 17:14
Automatically creates a new tag and AI generated description for it
#!/bin/env bash
set -e
model="gpt-4o"
temperature=0.8
prompt="Below is the output of \`git log <latest_tag>..HEAD\`."`
`"\nPlease provide a perfect tag message."`
`"\nUse emojis in the message text when appropriate. Use past tense."`
@valmat
valmat / gitai.sh
Last active December 11, 2024 17:13
AI git commit filler
#!/bin/env bash
set -e
model="gpt-4o";
temperature=0.8;
prompt="Below is the output of \`git diff HEAD\`."`
`"\nPlease provide a perfect git commit message."`
`"\nAlways use an emoji as the first character. Use emojis in the message text when appropriate."`
@valmat
valmat / change_owner.c
Created December 1, 2022 12:10
function to change process owner (if required)
#include <unistd.h>
// true if current user is not root
// or true if owner changing is not required (targ_uid == 0)
// or true if current user is root and uid changed
// false otherwise (owner changing was unsuccessful)
bool change_owner(unsigned int targ_uid) noexcept
{
return
(0u != getuid()) || // made sure that src_uid == 0 (source is root)
@valmat
valmat / proxy.c
Created December 1, 2022 10:14
Simple and fast async libevent tcp proxy
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/listener.h>
#include <event2/util.h>
@valmat
valmat / fixdell
Last active April 21, 2022 06:48
Fix DELL freezes
#!/bin/bash
### BEGIN INIT INFO
# Provides: fixdell
# Required-Start: $local_fs $syslog $named
# Required-Stop: $local_fs $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Fix DELL freezes
# Description: startup script for Fix DELL freezes
### END INIT INFO
@valmat
valmat / entropy_benchmark.cpp
Created February 8, 2022 11:32
Entropies benchmark
#include <iostream>
#include <cmath>
#include <chrono>
struct BenchResult
{
std::chrono::nanoseconds duration;
double sum;
};
@valmat
valmat / splitRange.cpp
Created January 16, 2022 17:22
Evenly splits the values range for load balancing CPU cores
#include <iostream>
#include <utility>
#include <vector>
// Равномерно разделяет диапазон значения
// Для балансировки нагрузки на ядра CPU
std::vector<std::pair<int, int>>
splitRange(int from, int to, uint threads) noexcept
{
std::vector<std::pair<int, int>> pairs;