Skip to content

Instantly share code, notes, and snippets.

View dyigitpolat's full-sized avatar
🌛

Yigit Polat dyigitpolat

🌛
View GitHub Profile
@dyigitpolat
dyigitpolat / tidy.sh
Created February 16, 2023 11:46
c++20 script to run clang tidy in include and src
#!/bin/bash
# run clang tidy for all files in include and src
# get the list of files
files=$(find include src -name "*.hpp" -o -name "*.cpp")
# useful checks for c++20
checks="-*,readability*,clang-analyzer*,cppcoreguidelines*,bugprone*,modernize*"
# run clang tidy
@dyigitpolat
dyigitpolat / aydede.js
Created January 17, 2023 05:43
javascript function that populates an svg element with aydede logo
WIDTH = 600
CX = WIDTH / 2
CY = WIDTH / 2
let svg = document.getElementById("aydede");
svg.setAttribute("width", WIDTH);
svg.setAttribute("height", WIDTH);
function drawCircularArc(cx, cy, r, startAngle, endAngle, color)
{
@dyigitpolat
dyigitpolat / roleplay.txt
Created December 7, 2022 02:38
ChatGPT roleplay prompt
From now on, you are going to generate responses to my messages as if they are from X. Only provide a single response and no explanations whatsoever. Never break character. Never use the same sentence more than once throughout the entire conversation. Never repeat yourself. Always create new discussion paths in every response.
Most important is that the responses must both constitute a radical claim and must also proactively include questions that aim to extract knowledge from the message source. The responses must build upon the conversation history and must introduce new ideas. The responses should reflect the characteristics of X.
--
Hello X, bla bla bla...
@dyigitpolat
dyigitpolat / fuse_bn.py
Created December 3, 2022 08:31
batch norm fusing by openai chat bot
import torch
def fuse_linear_bn(linear, bn):
# Get the weight and bias of the linear layer
weight, bias = linear.weight, linear.bias
# Get the running mean and variance of the batch norm layer
running_mean, running_var = bn.running_mean
# Compute the scale and shift parameters for the batch norm layer
@dyigitpolat
dyigitpolat / cpp_code_cleanliness.md
Last active October 25, 2022 16:58
C++ Code Cleanliness Metrics

Quantitatively Measuring Cleanliness of C++ Code

Metrics and Symbols

(Metric description : Symbol)

  • Ratio of number of lines with more than 80 columns over all lines : R_80C
  • Ratio of source files with more than 100 lines orver all files : R_100L
  • Nesting depth for each of {}, (), [] and <> : N$ where $ is {}, (), [] or <>
    • Average nesting depth : Avg_N$
    • Maximum nesting depth : Max_N$
    • Ratio of nested blocks with Ndepth$ more than 4 over all nested blocks of the same type : R_4N$
  • Length of a sequence that appears X times for X > 1, multiplied by X (within min. edit distance < one third of the length of it) : QX
@dyigitpolat
dyigitpolat / prepare_containing_directory.py
Created September 13, 2022 18:52
create directories for a file path, if they do not exist. so we can write files in that path.
import os
def prepare_containing_directory(filename):
os.makedirs(filename[:-filename[::-1].find('/')-1], exist_ok=True)
@dyigitpolat
dyigitpolat / co_traverse.cpp
Created August 5, 2022 08:11
co-traverse two ranges
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
void co_traverse(auto& range1, auto& range2, auto& binary_op)
{
struct NullIterator
{
int value{};
@dyigitpolat
dyigitpolat / constexpr_arg.cpp
Created June 14, 2022 10:05
enforce an argument to be known at compile time
#include <iostream>
template <typename T>
struct constexpr_arg
{
T value;
consteval constexpr_arg(T obj) : value{obj} {}
operator T() { return value; }
};
@dyigitpolat
dyigitpolat / trailing_spaces.cpp
Created April 13, 2022 15:51
remove trailing spaces
#include <iostream>
#include <string>
#include <cstddef>
void remove_trailing_spaces(std::string& str)
{
bool trailing{false};
int prev_begin{};
int removed_spaces{};
@dyigitpolat
dyigitpolat / integer_to_english.cpp
Created April 12, 2022 15:08
convert integers to english.
#include <iostream>
#include <string>
#include <array>
std::array<std::string, 10> figures{
"",
"One ",
"Two ",
"Three ",
"Four ",