Skip to content

Instantly share code, notes, and snippets.

Avatar

Ilya Konstantinov ikonst

View GitHub Profile
@ikonst
ikonst / mocker.py
Created Nov 11, 2021
pytest_mock with patch.method
View mocker.py
import gc
import sys
import types
import unittest.mock
from typing import Any
from typing import Callable
from typing import Generator
from typing import Optional
from typing import TYPE_CHECKING
@ikonst
ikonst / eabi-wchar.c
Last active Sep 28, 2020
Patches ELF (EABI) ARM attribute Tag_ABI_PCS_wchar_t.
View eabi-wchar.c
/*
* Patches ELF (EABI) ARM attribute Tag_ABI_PCS_wchar_t.
*
* This utility's chief purpose is to remove the flag indicating sizeof(wchar_t)
* from ARM EABI binaries -- or more precisely, setting it to 0 (= undefined).
*
* It is useful to mark libraries which don't use wchar_t at all as wchar_t-width-agnostic.
* This way, they can be linked to both sizeof(wchar_t)=2 and sizeof(wchar_t)=4 programs
* without any warnings.
*
@ikonst
ikonst / ActiveDirectoryToVcf.vbs
Created Aug 22, 2012
Gets Active Directory user information into a VCF file of VCards you can import into your phone or contacts app
View ActiveDirectoryToVcf.vbs
set iAdRootDSE = GetObject("LDAP://RootDSE")
namingContext = iAdRootDSE.Get("defaultNamingContext")
If WScript.Arguments.Count = 1 Then
namingContext = WScript.Arguments.Item(0)
Else
Wscript.Echo "Usage: ActiveDirectoryToVcf.vbs [Naming Context]"
Wscript.Echo "Default path is " & namingContext
End If
@ikonst
ikonst / cfdata.py
Last active Mar 19, 2020
LLDB extension for saving CFData to local file; useful for remote iOS debugging
View cfdata.py
'''
INSTALLING
curl --create-dirs -o ~/.lldb/cfdata.py https://gist.githubusercontent.com/ikonst/364af37c44e5f549b722/raw/cfdata.py \
&& echo 'command script import ~/.lldb/cfdata.py' >> ~/.lldbinit
USING
(lldb) cfdata_save some_cfdata /Users/john/foo
(lldb) cfdata_save some_nsdata /Users/john/bar
@ikonst
ikonst / addsym.cpp
Last active Feb 19, 2020
Adds IDA symbols as WinDbg synthetic symbols
View addsym.cpp
// Adds IDA symbols as WinDbg synthetic symbols
//
// Original code by 'blabb'.
//
// See:
// http://www.woodmann.com/forum/entry.php?262-addsym-windbg-extension-%28extension-to-load-names-from-ida-to-windbg%29
// http://reverseengineering.stackexchange.com/questions/3850/importing-list-of-functions-and-addresses-into-windbg
#include <engextcpp.hpp>
View mov2gif.sh
#!/bin/sh -e
# Converts a Quicktime movie to a GIF aniamtion.
# Useful for screen recordings.
# Preliminary step with palette required to make it look good
# without dithering artifacts.
FPS=10
PALETTE=$(mktemp).png
MOV=$1
@ikonst
ikonst / abort_on_dc.py
Last active May 14, 2019
Example of a gevent-based Flask server that aborts when downstream disconnects
View abort_on_dc.py
"""
Implements a behavior similar to:
- Go srv's cancelation of context on downstream disconnect
- PHP (unless `ignore_user_abort` is true)
"""
import gevent.monkey
gevent.monkey.patch_all()
from contextlib import contextmanager
from flask import Flask
View abort_on_eof.py
from contextlib import contextmanager
from functools import wraps
from socket import socket as socket_type, MSG_PEEK
from typing import Set
import flask
import gevent
def _abort_on_eof_watchdog(socket: socket_type, greenlets: Set[gevent.Greenlet]) -> bool:
@ikonst
ikonst / private.xml
Created Mar 18, 2016
Microsoft L5V-00001 Sculpt Ergonomic Desktop Keyboard and Mouse — private.xml for Karabiner
View private.xml
<?xml version="1.0"?>
<root>
<!--
Based on:
https://blog.yorkxin.org/posts/2014/04/12/microsoft-sculpt-mobile-mouse-and-mac/
Button 4 is the side button (located by the blue Windows button).
This allows you to map the Windows button as Button 5.
1. brew cask install karabiner
View NSData+GStreamer.h
@import Foundation;
#include <gst/gst.h>
@interface NSData (GStreamer)
- (GstBuffer *)gstBuffer;
@end
@interface NSMutableData (GStreamer)