Skip to content

Instantly share code, notes, and snippets.

View vpetrigo's full-sized avatar

Vladimir Petrigo vpetrigo

  • Poland, Kraków
View GitHub Profile
@vpetrigo
vpetrigo / gist:eb8d3104cbbec6a52017
Created June 19, 2015 11:10
Python retrieve data from windows registry
"""
Passing through a Windows registry key entry
Provide a needed registry key and a sub_key you want to retrieve values from
"""
path = r'HARDWARE\DEVICEMAP...'
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path) as key:
sub_keys, values, modified = winreg.QueryInfoKey(key)
for i in range(values):
@vpetrigo
vpetrigo / script.bat
Created August 4, 2015 11:39
Notepad++ command for building pdf from tex file
:: Use Notepad++ Run dialog
cmd /K cd /D $(CURRENT_DIRECTORY) && pdflatex $(FILE_NAME)
@vpetrigo
vpetrigo / subtree_size.sql
Last active November 13, 2015 09:54
Find the size of subtree in a PostgreSQL table which represents adjacency list relations
-- For example we have such table:
-- Table
-- id parent_id
-- -------------
-- 0 NULL
-- 1 0
-- 2 0
-- 3 1
-- 4 1
--
@vpetrigo
vpetrigo / ltree_to_nested.sql
Last active July 18, 2023 04:35
Generate nested set structure from PostgreSQL ltree structure
CREATE VIEW anc_and_des AS
SELECT
m.*,
-- Count all descendats of a vertice
( SELECT COUNT(*)
FROM KeywordLtree AS d
WHERE m.path @> d.path
) AS descendants,
-- Count all ancestors of a vertice
( SELECT COUNT(*)
@vpetrigo
vpetrigo / regex_cpp.cpp
Created November 30, 2015 20:54
C++ regex difference between regex_search and regex_match
#include <regex>
#include <iostream>
#include <string>
using namespace std;
class RegExpSearch {
public:
static std::smatch check_string(const std::regex &re, const std::string &s) {
std::smatch matches;
@vpetrigo
vpetrigo / smallalloc.cpp
Created December 23, 2015 12:00
Small Allocator C++
class SmallAllocator {
private:
union Header {
using Align = long;
struct {
Header *next;
size_t size;
} s;
@vpetrigo
vpetrigo / generate_random_key.cpp
Last active February 1, 2016 11:13
Random 32 hex-character string
#include <iostream>
#include <chrono>
#include <fstream>
#include <array>
#include <random>
#include <cstddef>
void key_gen(std::ofstream& fout);
int main() {
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
// as a directory name in Linux cannot be greater than 256
// characters
#define MAX_INPUT_SIZE 256
@vpetrigo
vpetrigo / update-pkg.bat
Created July 22, 2016 19:32
Batch files and shell scripts for Python packages via pip
@echo off
rem update system Python packages on Windows
FOR /F "usebackq" %%p IN (`pip list -o`) DO pip install -U %%p
@vpetrigo
vpetrigo / lcd_numbers.py
Created August 5, 2016 20:37
LCD like numbers
# Возможный вывод
# x-------------------------------------------------x
# | -- -- -- -- -- -- -- -- |
# || | | | | | | | | | | | | ||
# || | | | | | | | | | | | | ||
# | -- -- -- -- -- -- -- |
# || | | | | | | | | | | | ||
# || | | | | | | | | | | | ||
# | -- -- -- -- -- -- -- |
# x-------------------------------------------------x