Skip to content

Instantly share code, notes, and snippets.

@eginez
eginez / mat_mul.rs
Created June 16, 2024 23:21
Mat mul but in rust
use rand::Rng;
use std::time::SystemTime;
fn rand_float() -> f32 {
rand::thread_rng().gen::<f32>()
}
fn calcmatrix(matrix: Vec<Vec<Vec<f32>>>, indices: Vec<Vec<usize>>, big_size: usize) -> Vec<f32> {
let mut res = vec![0.0; big_size];
@eginez
eginez / mat_mul.c
Created June 16, 2024 23:18
Mat multiplication
// gcc -O3 one.c && ./a.out
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
float rand_float() { return (float)rand() / (float)RAND_MAX; }
float *calcmatrix(float ***matrix, int **indices, int big_size) {
float acc = 1;
@eginez
eginez / gh_logs.sh
Last active May 22, 2023 00:53
Github workflow logs in the command line
function gh_logs() {
#needs fzf, jq, github cli
branch_name=${1:-}
repo_name=
if [[ -n $2 ]]; then
repo_name="-R$2"
fi
job_name=$(gh $repo_name pr checks $branch_name|fzf|cut -d$'\t' -f1)
run_id=$(gh $repo_name pr checks $branch_name|grep "$job_name"|cut -d'/' -f8)
echo run id: $run_id
@eginez
eginez / compile_commands.json
Created March 13, 2023 04:14
Gcc compile commads for cpython
[
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-Wsign-compare",
"-Wunreachable-code",
"-DNDEBUG",
"-g",
"-fwrapv",
# load data index on date
# time series data like credit card transactions for example
df = pd.read_csv('~/Downloads/time_series_data.csv', index_col='Date', parse_dates=True)
# group by apply data and sum
df2 = df.groupby(pd.Grouper(freq='Y')).sum()
#df2 now contains sumarized data
# show perenctiles for example
df2.quantile([0.1, 0.5, 0.8, 0.9, 0.95])
@eginez
eginez / cors_server.py
Last active April 20, 2022 01:08
Python CORS simple http server
from http.server import HTTPServer, SimpleHTTPRequestHandler, test
import sys
class CORSRequestHandler (SimpleHTTPRequestHandler):
def _send_cors_headers(self):
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Methods", "GET,POST,OPTIONS")
def end_headers (self):
@eginez
eginez / one.sh
Last active January 3, 2022 18:55
Python build configurations
python -c "import sysconfig; print('-fprofile-use' in (sysconfig.get_config_var('PY_CFLAGS') + sysconfig.get_config_var('PY_CFLAGS_NODIST')))"
@eginez
eginez / init.vm
Created August 20, 2021 00:22
neovim setup
call plug#begin()
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-treesitter/playground'
Plug 'hrsh7th/nvim-compe'
Plug 'tjdevries/colorbuddy.vim'
Plug 'tjdevries/gruvbuddy.nvim'
call plug#end()
@eginez
eginez / one.md
Last active August 12, 2021 02:17
Docker global limits via croups

Create slice file to limit resources: /etc/systemd/system/docker.slice

[Unit]
Description=Slice with MemoryLimit of 80% for docker
Before=slices.target

[Slice]
MemoryAccounting=true
MemoryMax=10%
@eginez
eginez / main.jl
Created July 3, 2021 18:55
Julia read stdout of proc
out = Pipe()
p = run(pipeline(`top`, stdout=out), wait=false)
## Now p is running in the background
## You can read out
output = String(read(out, 1024)) ## read() reads until eof, which is not what I need.
line = readline(out)
kill(p)