Skip to content

Instantly share code, notes, and snippets.

@dtrugman
dtrugman / pandas.py
Created June 27, 2023 22:25
Pandas cheat sheet
import pandas as pd
# Create new DataFrame
data = {
"FirstName" : ["Daniel", "Jenny", "Mia"],
"LastName" : ["Trugman", "Altman", "Herman"],
"Age" : [35, 36, 28]
}
df = pd.DataFrame(data, index = [1, 2, 3])
df.head()
@dtrugman
dtrugman / git-describe
Last active November 2, 2021 08:59
Describe git projects
#!/bin/bash
git-describe() {
for dir in *; do
[[ -d "$dir" ]] || continue
[[ -d "$dir/.git" ]] || continue
local branch="$(cd "$dir"; git rev-parse --abbrev-ref HEAD)"
echo "$dir -> $branch"
done
@dtrugman
dtrugman / rename_by_timestamp.py
Last active January 16, 2021 12:09
Set all files names inside a directory according to their creation date
'''
Copyright (c) 2021 Daniel Trugman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@dtrugman
dtrugman / ivagrant
Last active October 25, 2021 18:57
Interactive Vagrant menu
#!/bin/bash
# This is a helper script for using vagrant interactively
# Just run it without any parameters and follow the menu
ivagrant() {
declare vm_idx="$1"
declare vm_cmds="${@:2}"
# Read records
@dtrugman
dtrugman / memre.py
Last active January 27, 2021 14:59
Python-based real-time process memory reader
#!/usr/bin/python3
import sys
from os import getuid
from signal import pthread_kill
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from binascii import hexlify
class MemoryRegion():
def __init__(self, line):
@dtrugman
dtrugman / Makefile
Created April 21, 2018 20:36
Simple all-around CPP Makefile
CXX = g++
SRC = $(wildcard *.cpp)
OBJ = $(SRC:.cpp=.o)
CPPFLAGS = --std=c++14
LDFLAGS =
app: $(OBJ)
$(CC) $(CPPFLAGS) -o $@ $^ $(LDFLAGS)
@dtrugman
dtrugman / args-parser.c
Created April 21, 2018 19:45
Argument parsing in C
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>
int main(int argc, char ** argv)
{
const char * mystr = "default";
int myint = 0;
float myfloat = 0.0;
@dtrugman
dtrugman / defer.hpp
Last active April 22, 2024 00:34
GO's defer-like implementation for CPP
/*
* Copyright (c) 2020-present Daniel Trugman
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*