Skip to content

Instantly share code, notes, and snippets.

@yegappan
yegappan / VimScriptForPythonDevelopers.MD
Last active Jan 21, 2023
Vim script for Python Developers
View VimScriptForPythonDevelopers.MD

Vim Script for Python Developers

This is a guide to Vim Script development for Python developers. Sample code for the various expressions, statements, functions and programming constructs is shown in both Python and Vim Script. This is not intended to be a tutorial for developing Vim scripts. It is assumed that the reader is familiar with Python programming.

For an introduction to Vim Script development, refer to usr_41.txt, eval.txt and Learn Vimscript the Hard Way

For a guide similar to this one for JavaScript developers, refer to Vim Script for the JavaScripter

This guide only describes the programming constructs that are present in both Python and Vim. The constructs that are unique to Vim (e.g. autocommands, [key-mapping](https://vimhelp.org/map.txt.html#key-m

@jdthorpe
jdthorpe / Extending python-docx.md
Last active Feb 3, 2022
Extending python-docx
View Extending python-docx.md

Extending python-docx

Background

I was recently tasked with scraping data from a few thousand of word documents each of which contained nested docx documents which were referenced by w:altChunk elements in the body of the main ./word/document.xml file, like so:

@paragonie-scott
paragonie-scott / crypto-wrong-answers.md
Last active Nov 24, 2022
An Open Letter to Developers Everywhere (About Cryptography)
View crypto-wrong-answers.md
@julianlam
julianlam / expose-directory-on-host-to-lxc-container.md
Last active Sep 25, 2022
Exposing a directory on the host machine to an LXC container #blog
View expose-directory-on-host-to-lxc-container.md

Exposing a directory on the host machine to an LXC container

  1. Log into the container and create an empty directory, this will be the mount point
  2. Log out and stop the container.
  3. Open to your container's config file
    • For regular LXC containers: /var/lib/lxc/mycontainer/config
    • For unprivileged LXC containers: $HOME/.local/share/lxc/mycontainer/config
  4. Add a new line above the lxc.mount directive, that follows the format below. Substitute proper paths as necessary:
    • lxc.mount.entry = /path/to/folder/on/host /path/to/mount/point none bind 0 0
  • Both of these paths are relative to the host machine.
View Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@alukach
alukach / admin.py
Created Jan 5, 2015
Custom Django Admin Form via Fake Model
View admin.py
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django.shortcuts import render
from my_app.forms import CustomForm
class FakeModel(object):
class _meta:
app_label = 'my_app' # This is the app that the form will exist under
View simhash links
@miki725
miki725 / .bash_prompt.sh
Last active Jan 12, 2023
Custom bash prompt which displays: (virtualenv) user:/path (git-branch)
View .bash_prompt.sh
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the active virtualenv
# * the branch of the current git/mercurial repository
# * the return value of the previous command
# * the fact you just came from Windows and are used to having newlines in
# your prompts.
@Hamatti
Hamatti / git_stuff.sh
Created Jan 16, 2014
Added some alias stuff to display git branch description everytime I do git status (or gs as it's aliased for me). That helps me keep on track with branches that are named like issue-[nro] or fix-[nro].
View git_stuff.sh
function parse_git_branch_name {
git rev-parse --abbrev-ref HEAD
}
function parse_git_description {
git config branch.$(parse_git_branch_name).description
}
alias gs='echo $(parse_git_branch_name): $(parse_git_description) && git status'
@amarandon
amarandon / iwatch
Last active Dec 22, 2021
Give this script a command line and it will execute it everytime you update a file under the current directory. Great to run unit tests, build documentation, etc. Based on idea from @AntoineCezar
View iwatch
#!/bin/sh
# requires inotify-tools
VIM_BACKUP_PATTERN=".*\.sw."
$* # First execution of the command
while true; do
inotifywait --exclude=$VIM_BACKUP_PATTERN -q -e create,modify,delete -r .