Skip to content

Instantly share code, notes, and snippets.

View barron9's full-sized avatar
🌴

berkin tatlisu barron9

🌴
View GitHub Profile
@barron9
barron9 / custom_semaphore_cancel_support.py
Last active February 27, 2025 21:19
a simple semaphore solution with cancel support (with sendable and without sendable)
import Foundation
// A custom error type for cancellation
enum TaskError: Error {
case canceled
}
// A struct to manage tasks and handle cancellation
class ConcurrentTaskManager {
@barron9
barron9 / titanic_kaggle_contest_classif.py
Last active February 21, 2025 10:27
Titanic - Machine Learning from Disaster / score 0.80382/ feature mods.
import re
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.ensemble import GradientBoostingClassifier, RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import LabelEncoder
from sklearn.impute import SimpleImputer
import pandas as pd
from sklearn.ensemble import AdaBoostClassifier
from sklearn.model_selection import train_test_split
import xgboost as xgb
@barron9
barron9 / inverted-pendulum-v5.py
Last active December 31, 2024 22:36
q solution for inverted pendulum
import gymnasium as gym
import numpy as np
from tqdm import tqdm
import numpy as np
import matplotlib.pyplot as plt
import pickle
import os
env_train = gym.make('InvertedPendulum-v5')
# Define the dimensions of your state space
dim1 = 5
@barron9
barron9 / TD methods.py
Created December 30, 2024 13:48
TD methods.py
# Q-learning Update rule
def q_learning_update(Q, state, action, reward, next_state, lr, discount):
"""
Q-learning update rule
Q(s, a) <- Q(s, a) + α * [r + γ * max_a Q(s', a) - Q(s, a)]
"""
# Compute the Q-value update using Q-learning formula
Q[state][action] += lr * (reward + discount * np.max(Q[next_state]) - Q[state][action])
return Q
@barron9
barron9 / gist:6ae6e6ee86384c02f1863cd76889f995
Last active October 17, 2023 05:59
bufferbloat_fix_workaround, bufferbloat çözümü tplink Vc220-g3u
verified on Tplink Vc220-g3u
Dns cache disable from your os
Dhcp ip rental set 1 or 5 or 8 min not like 60
Ağ geçidi sil
qos [ssid] = (max download) - 1000~
Reset
;)
dns cache i windowstan disable edin
#include <iostream>
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
std::queue<int> dataQueue;
std::mutex mtx;
std::condition_variable cv;
const int maxQueueSize = 10; // Maximum queue size before backpressure is applied
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
int main(){
std::vector<std::pair<int, int>> vec;
std::vector<std::pair<int, int>> vecquen;
@barron9
barron9 / attention.cpp
Created September 10, 2023 05:33
attention
#include <iostream>
#include <vector>
#include <cmath>
#include "attention.h"
// Function to compute the attention weights
std::vector<double> computeAttentionWeights(const std::vector<double>& query, const std::vector< std::vector<double> >& keys) {
int numKeys = keys.size();
std::vector<double> attentionWeights(numKeys, 0.0);
double totalWeight = 0.0;
import Foundation
class ThreadInterruptionSimulator {
var threads: [Thread] = []
var interrupterThread: Thread?
// Function to simulate work done by threads
func worker(threadNum: Int) {
// for _ in 0..<5 {
@barron9
barron9 / elf.h
Created August 12, 2023 08:13 — forked from mlafeldt/elf.h
elf.h for OSX
/* This is the original elf.h file from the GNU C Library; I only removed
the inclusion of feature.h and added definitions of __BEGIN_DECLS and
__END_DECLS as documented in
https://cmd.inp.nsk.su/old/cmd2/manuals/gnudocs/gnudocs/libtool/libtool_36.html
On macOS, simply copy the file to /usr/local/include/.
Mathias Lafeldt <mathias.lafeldt@gmail.com> */
/* This file defines standard ELF types, structures, and macros.