Skip to content

Instantly share code, notes, and snippets.

View floer32's full-sized avatar

Michael Floering floer32

  • 02:20 (UTC -07:00)
View GitHub Profile
@floer32
floer32 / python_bind_function_as_method.py
Created February 11, 2015 01:42
Bind Python function as method
# based on: http://stackoverflow.com/questions/1015307/python-bind-an-unbound-method#comment8431145_1015405
def bind(instance, func, as_name):
""" Turn a function to a bound method on an instance
.. doctest::
>>> class Foo(object):
... def __init__(self, x, y):
... self.x = x
... self.y = y
@floer32
floer32 / tupperware.py
Last active September 26, 2022 12:13
recursively convert nested dicts to nested namedtuples, giving you something like immutable object literals
from UserDict import IterableUserDict
import collections
__author__ = 'github.com/hangtwenty'
def tupperware(mapping):
""" Convert mappings to 'tupperwares' recursively.
@floer32
floer32 / Uniform Type Identifiers (UTI).md
Last active August 5, 2022 18:06
I always forget where to find this, so here's a copy. It's an old-but-still-useful thing from the Apple Developer documentation archive, and it's from 2005 (whoa, right?)

What's a Uniform Type Identifier?

Each UTI provides a unique identifier for a particular file type, data type, directory or bundle type, and so on. In addition, other type identifier namespaces for a particular type can be grouped under one UTI, with utility functions available to translate from one format to another.

What's the table below?

The following tables list uniform type identifiers (UTIs) that are declared by the system as of OS X v10.4. [Which was released in 2005. That means it's NOT up to date. Apple Developer stuff has the up to date docs. Still, these can be useful for scripting, Alfred Workflows, and so on.]

Note: T

@floer32
floer32 / _fix_pip_import_error.md
Last active June 24, 2022 10:44
fix that pesky "ImportError: No module named packaging.version" problem. Or more generally, if you need to fix pip using pip, just make sure you do "python -m pip" instead of straight-up "pip".

It can come up while installing anything really. I'm not sure exactly which versions of pip are affected, I know I had 1.5.6 and it was affected.

These examples are grabbed from my system level Python, but of course you should use a virtualenv.

  Running setup.py install for simplegeneric
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Library/Python/2.7/site-packages/setuptools/__init__.py", line 12, in <module>
        import setuptools.version
@floer32
floer32 / git ribbon, git catchup.md
Last active May 25, 2022 17:41
git ribbon, git catchup

How I keep up with changes on main

[1/2] These two git aliases: git ribbon, git catchup

I've used these for years (found here)

  • git ribbon to mark latest main you've reviewed (like a ribbon in a journal)
  • git catchup to review diff since then. (then do git ribbon again after reviewing, so it's ready for tomorrow.)

In your ~/.gitconfig, [aliases] section:

@floer32
floer32 / centos_python_env_setup
Last active May 2, 2022 03:47 — forked from stantonk/doit
CentOS 6: Install Python 2.7.4, pip, virtualenv, and virtualenvwrapper on CentOS (plus some bonus items at the end if you want). You should probably run with `sudo`.
#!/bin/bash
# Source: http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/
# Install stuff #
#################
# Install development tools and some misc. necessary packages
yum -y groupinstall "Development tools"
yum -y install zlib-devel # gen'l reqs
@floer32
floer32 / matrix_multiplication_refresher.md
Last active April 13, 2022 11:59
Matrix multiplication refresher: develop your intuition for matrix multiplication! (Or, "matrix multiplication for dummies")

A refresher on matrix multiplication. Because your math classes were years ago. Here's the order I recommend:

  1. TED-Ed video — How to organize, add and multiply matrices - Bill Shillito (only 5 minutes)
  2. betterexplained.com"An Intuitive Guide to Linear Algebra" by Kalid Azad
  3. mathinsight.org: "Matrices and linear transformations"
  4. Read some of the answers on math.stackexchange.com. You've been studying the general definition of matrix multiplication. You may wonder: "Are there other ways to define the product of two matrices?" These resources will answer, yes, there are other ways, but also explain why this general definition is the standard way.
  5. [What is the intuitive way of thinking about multiplication of m
@floer32
floer32 / auto-open-devtools-for-tabs.md
Last active December 3, 2021 06:54
memo - how to open chrome with the javascript console open by default, on a mac
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --auto-open-devtools-for-tabs

Canary:

/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --auto-open-devtools-for-tabs
@floer32
floer32 / HOWTO_install_xmobar_with_all_extensions.sh
Last active September 16, 2021 08:05
HOWTO xmobar with all extensions in Arch Linux
#!/bin/sh
# install cabal-install if necessary
sudo pacman -S cabal-install
# preparing to install xmobar with all extensions
sudo pacman -S alex
yaourt haskell-language-c-03
sudo cabal install --global c2hs
sudo cabal install --global alsa-mixer
@floer32
floer32 / How to make VS Code focus the Debug sidebar instead of Explorer.md
Last active March 26, 2021 01:01
How to make VS Code focus the Debug sidebar instead of File Explorer

It took me a little bit to find this setting so I'm writing it down for friends.

After you finish a debug session in VS Code, it may change the sidebar's focus back to the File Explorer.

I don't think it is the default setting, but mine was set that way (and I didn't remember that).

To change it in your settings JSON: