Skip to content

Instantly share code, notes, and snippets.

View Snawoot's full-sized avatar

Snawoot

View GitHub Profile
@Snawoot
Snawoot / build-efitools-1.9.2.sh
Last active May 14, 2019 17:59
Builds efitools-1.9.2 on Fedora 30. Run it in source directory.
#!/bin/sh
make CRTOBJ=crt0-efi-x64.o \
LDSCRIPT=elf_x64_efi.lds \
LDFLAGS='-nostdlib -L /usr/lib64/gnuefi -shared -Bsymbolic $(CRTOBJS) -L $(CRTPATH) -L /usr/lib -L /usr/lib64 -L /usr/lib/gnuefi -L /usr/lib64/gnuefi -T $(LDSCRIPT)' \
INCDIR='-I$(TOPDIR)include -I/usr/include/efi -I/usr/include/efi/x64 -I/usr/include/efi/protocol' && \
sudo make install
@Snawoot
Snawoot / fedora_clean_kernels.sh
Created May 11, 2019 00:07
Cleans old kernels in Fedora
#!/bin/sh
dnf remove $(dnf repoquery --installonly --latest-limit=-1 -q)
#!/usr/bin/env python3
import gc
import time
class MyClass:
pass
class GCProfiler:
@Snawoot
Snawoot / gist:a3a92c310381a5cab4d7b6a0756db936
Created April 4, 2019 16:26
GPG agent setup for Yubikey
moreentropy 20 hours ago [-]
This was exactly my experience from two years ago. But to my surprise with recent gpg2 versions most of those issues are gone (plus EC ssh key files are supported, older gpg-agent could only do RSA)
scdaemon used to crash all the time, that doesn't happen anymore. GPG doesn't lock the card so I have to stop scdaemon to use it w/ other apps.
So for the last half year I've happily used gpg-agent/scdaemon also as SSH agent and it works really well without any issues.
But setting this up (w/ Ubuntu+Gnome) is still a ridiculous task:
@Snawoot
Snawoot / lualib.conf
Created February 17, 2019 02:41
Snippets for remote nginx reload
# located at /etc/nginx/conf.d/lualib.conf
lua_package_path "/etc/nginx/lualib/?.lua;;";
@Snawoot
Snawoot / formatFilename.py
Created February 1, 2019 08:01 — forked from seanh/formatFilename.py
Turn any string into a valid filename in Python.
def format_filename(s):
"""Take a string and return a valid filename constructed from the string.
Uses a whitelist approach: any characters not present in valid_chars are
removed. Also spaces are replaced with underscores.
Note: this method may produce invalid filenames such as ``, `.` or `..`
When I use this method I prepend a date string like '2009_01_15_19_46_32_'
and append a file extension like '.txt', so I avoid the potential of using
an invalid filename.
@Snawoot
Snawoot / ping.py
Last active April 11, 2024 03:52
Ping implementation for Windows using ICMP API
import ctypes
import ctypes.wintypes
import argparse
import socket
import struct
import os
INVALID_HANDLE_VALUE = ctypes.c_void_p(-1).value
./configure \
--extra-version="yarmak" \
--enable-gpl \
--disable-stripping \
--enable-avresample \
--enable-avisynth \
--enable-gnutls \
--enable-ladspa \
--enable-libass \
--enable-libbluray \
@Snawoot
Snawoot / psychologist_tips.md
Last active November 10, 2018 20:53
Советы психолога

Советы психолога

Вопрос: Я нравлюсь одному парню в универе, я активно с ним флиртую и старательно поддерживаю его надежды на нашу близость. В результате чего он делает мне курсовые, лабораторные, чинит компьютер и перемещает по моей просьбе тяжелые предметы. Это всё, конечно, хорошо, но мне этого не достаточно. Подскажите, пожалуйста, как мне получить абсолютную власть над человеком, подавить в нём личность и разрушить веру в себя? Ирина.

import mock
# Open mocked text file in text mode
with mock.patch('__main__.open', mock.mock_open(read_data='aaaa')) as m:
with open('foo', 'r') as h:
print(type(h.read()))
# Open mocked text file in binary mode
with mock.patch('__main__.open', mock.mock_open(read_data='aaaa')) as m:
with open('foo', 'rb') as h: