Skip to content

Instantly share code, notes, and snippets.

View andreberg's full-sized avatar
💭
I may be slow to respond.

André Berg andreberg

💭
I may be slow to respond.
View GitHub Profile
@andreberg
andreberg / python_extension_no_editor_outline.md
Last active February 26, 2020 15:00
[VSCode: Tips and Tricks] Collection tips and tricks, quick fixes and short-hand solutions to common snags. #vscode #tips #tricks #quickfix

Problem

No symbols shown in editor outline when opening a .py file.

Symptoms

Message No symbols found in document '<document name>.py displayed in editor outline panel.

Possible causes

@andreberg
andreberg / python.json
Last active December 22, 2024 21:48
[VSCode: Python Snippets] Python snippet collection. #vscode #python #snippets #template #json
{
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@andreberg
andreberg / vscode_slasher.ts
Created February 26, 2020 13:54
[VSCode: Slasher] TextEditor command extenison for converting between forward and backward slashes in a text selection. #vscode #extension #typescript #command #conversion
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
@andreberg
andreberg / TooltipsForGuiControls.ahk
Last active February 24, 2020 17:25
[GUI Tooltips] Shows how to attach tooltips to Gui controls on-the-fly and update them. Works with all AHK versions: ANSI+Unicode, 32/64bit. #autohotkey #ahk #gui
; ### Example Code #####
Gui,Add,Button,hwndbutton1 Gbut1,Test Button 1
Gui,Add,Button,hwndbutton2,Test Button 2
Gui,Add,Button,hwndbutton3,Test Button 3
AddTooltip(button1,"Press me to change my tooltip")
AddTooltip(button2,"Another Test Tooltip")
AddTooltip(button3,"A Multiline`nTest Tooltip")
Gui,show,,Test Gui
Return
@andreberg
andreberg / PoE-Macros.ahk
Last active June 21, 2022 18:16
[Path of Exile Autohotkey Macros] Shows how to bind some (really outdated!) commands to hotkeys. #pathofexile #poe #ahk #autohotkey #macros
#IfWinActive, Path of Exile ahk_class Direct3DWindowClass
#SingleInstance force
; Menu tooltip
Menu, tray, Tip, Path of Exile Macros
; NOTE: Adjust this path so it is correct.
; If you are using my PoE-Item-Info script you can find
; the tray icons inside its data directory.
Menu, tray, Icon, PoE Item Info\data\poe-web.ico
@andreberg
andreberg / pylong_from_bytearray.py
Last active February 24, 2020 18:00
[PyLong from ByteArray] Methods for reading and converting PyLong objects as defined in longobject.c. Made this to help me understand how Python's marshal interface deals with these objects when it commits the bytes making up the PyLong object to a binary pyc file. #cython #python #python3 #marshall #cpython #synalyzeitpro
#!/usr/local/bin/python3.3
'''
pylong_from_bytearray -- methods for reading and converting PyLong objects.
Ported from Python's C source code, specifically from marshal.c and longobj.c
Serialization of PyLong objects to marshal's bytecode format has the following
layout:
+--+--+--+--+--+--+--+--+--+
@andreberg
andreberg / pyc.grammar
Last active February 24, 2020 17:59
[Synalyze It Pro: Python 2 and 3 Bytecode Grammar] Targets .pyc and .pyo bytecode files. #synalyzeitpro #grammar #python #python3 #bytecode
<?xml version="1.0" encoding="UTF-8"?>
<ufwb version="1.5.1">
<grammar name="Python Bytecode" start="id:104" author="André Berg" email="[email protected]" fileextension="pyc, pyo" uti="public.data" complete="yes">
<description>Grammar for PYC and PYO files
Version: 8
Now works with pyc/pyo files generated by Python 2, Python 3.0-3.2 and Python 3.3.
References
@andreberg
andreberg / Timestamp.py
Last active February 24, 2020 17:48
[Synalyze It Pro: Timestamp Data Type Script] For displaying and manipulating the timestamp header bytes in a Python bytecode (pyc) file. #synalyzeitpro #userscript #python #bytecode
# Data type script for displaying and manipulating the
# timestamp header bytes in a Python bytcode (pyc) file.
#
# pyc header
# 8 16
# +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
# |X|X|X|X|0|D|0|A| |T|I|M|E|S|T|M|P|
# +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
# \______/\______/ \_______________/
# inc. cr/lf timestamp
@andreberg
andreberg / pyobjc_coregraphics_example1.py
Last active February 24, 2020 17:45
[PyObjC CoreGraphics API Example] Shows how to use the functional API of the CoreGraphics framework through PyObjC and Python 2.7. #pyobjc #python #coregraphics #quartz #macos #examples
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
#
# pyobjc_coregraphics_example1.py
# PyObjC Scripts
#
# Created by André Berg on 2013-07-09.
# Copyright 2013 Berg Media. All rights reserved.
#
# Example script that shows how to use
@andreberg
andreberg / benchmark decorator.py
Last active February 24, 2020 18:01
[Benchmark Decorator] Prints the time a function take to execute per call and cumulative total. Works with Python 2.7 and Python 3. #python #python3 #benchmark #decorator
# -*- coding: utf-8 -*-
#
# Created by André Berg on Jun 2, 2013.
# Copyright 2013 Berg Media. All rights reserved.
#
from functools import wraps, partial
def benchmark(func=None, prec=3, unit='auto', name_width=0, time_width=8):