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.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 / 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 / anaconda_add_custom_env_manually.md
Last active March 2, 2020 15:26
[Anaconda: Add Custom Env Manually] Configure environment with external Python interpreter. #anaconda #python #env #environment

NOTE: This solution is not permanent! Everytime Anaconda Navigator is being used to update the envs, ~/.conda/environments.txt will be re-created which will lose all manually added envs.

Add New Custom Env

  1. Navigate to ~/.conda
  2. Make directory <new_env_name> in ~/.conda/envs
  3. Edit ~/.conda/environments.txt to include ~/.conda/envs/<new_env_name>

Add Pre-Existing Env (soft-linked)

@andreberg
andreberg / creating_hard_and_soft_links_in_powershell.ps1
Last active May 9, 2020 19:44
[Creating hard and soft links using PowerShell] #weakshell #powershell #console #terminal #command
@andreberg
andreberg / fix_network_drives_missing_in_elevated_shell.ps1
Last active March 2, 2020 16:20
[From WeakShell to PowerShell] Fixing the broken mess that is 'PowerShell' so it resembles something actually worthy of its name. #powershell #weakshell #fixes #tips
# Reconnect PSDrives for network connections when running with elevated privileges
$elevated = (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
if( $elevated ) {
net use | ?{ $_ -match ":\s+\\\\" -and !$_.StartsWith("Unavailable") } | %{
$tokens = $_.split(":")
$psdrivename = $tokens[0][$tokens[0].length-1]
$path = $tokens[1].trim().split(" ")[0].trim()
if( !(get-psdrive | ?{ $_.Name -eq $psdrivename } )) {
write-host ( "Restoring PSDrive for {0}: {1}" -f $psdrivename, $path )
@andreberg
andreberg / houdini_read_point_attrib_values.py
Created November 17, 2020 17:47
[Read Point Attrib Values] Example for converting quaternions to euler angles. #houdini #hom #python #attribs
# read geometry from input node (otherwise inf recursion error)
n = pwd().inputs()[0]
g = n.geometry()
# here's how you access point attrib values from the geometry
# orient is a list of float values
orient = g.pointFloatAttribValues("orient")
x = orient[0]
y = orient[1]
z = orient[2]
w = orient[3]
@andreberg
andreberg / confluence_inline_css_styling.md
Last active January 13, 2021 17:09
[Confluence Inline CSS Styling] Make your inline code literals like paths, variable values etc. look nicer than admin intended. #confluence #css #styles #inline #markup #markdown

In Confluence use the Insert Markup featureset it to Markdown and add any CSS styles you want

for example:

<span style="background-color: #eee; border-top: 1px solid #aaa; border-bottom: 1px solid #aaa; font-family: monospace; padding: 2px;">
//path/to/folder/with/some_file.ext
</span>

easy copy+paste

@andreberg
andreberg / sphinx_rtd_theme_search_issue_fix.md
Created January 20, 2021 18:32
[Sphinx RTD Theme Search Fix] Fixes the hanging search. #python #documentation #docs #sphinx #read-the-docs #theme #bugfix

In site-packages\sphinx_rtd_theme > layout.html

After

{% if sphinx_version >= "1.8.0" %}
  	<script type="text/javascript" id="documentation_options" data-url_root="{{ pathto('', 1) }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>

Add

@andreberg
andreberg / get_active_object_bpy28.py
Created February 24, 2021 17:54
[Get Active Object] Access selected object from bpy scene context (blender 2.8) #blender #python #scene #context #object #scripting #blender28 #bpy
import bpy
active_object = bpy.context.view_layer.objects.active
@andreberg
andreberg / rename_files.py
Last active May 26, 2021 16:52
[Rename Files] Recursive regex file renamer #python #cli #files #renamer #script #batch #bulk
#!/usr/bin/python
# encoding: utf-8
import os
import re
import sys
import time
import argparse
from datetime import date