Skip to content

Instantly share code, notes, and snippets.

@bryan-lott
bryan-lott / ignored_context_manager.py
Last active August 29, 2015 14:01
Context Manager - Ignore Exceptions and Others
"""Not sure where this came from, but I suspect
it was from a python talk about making beautiful
code."""
from contextlib import contextmanager
@contextmanager
def ignored(*exceptions):
"""Ignore a provided list of exceptions."""
try:
@bryan-lott
bryan-lott / text_progress_bar.py
Created May 27, 2014 15:39
Text Progress Bar
"""I believe that this snippet of code
came from somewhere on stackoverflow."""
from __future__ import print_function
import sys, time
class ProgressBar:
def __init__(self, iterations):
self.iterations = iterations
self.prog_bar = '[]'
@bryan-lott
bryan-lott / _vimrc
Created November 5, 2014 22:31
VIM Config
if has('win32') || has('win64')
set runtimepath=$HOME/_vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/_vim/after
endif
" Usability & Appearance Options
filetype plugin indent on
syntax enable
" Turn on line numbering (turn off with "set nonu")
set nu
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]
@bryan-lott
bryan-lott / redshift_example_using_psycopg2.py
Created October 27, 2015 17:54
Example on how to connect to redshift using psycopg2
__author__ = 'fbaldo'
import psycopg2
import pprint
configuration = { 'dbname': 'database_name',
'user':'user_name',
'pwd':'user_password',
'host':'redshift_endpoint',
import re
import os
import sys
import subprocess
import signal
import threading
import time
import ltmain
def noop():
@bryan-lott
bryan-lott / reproduce_canvas_memory_increase.py
Created August 26, 2013 17:14
Code to reproduce memory issue with NavCanvas.NavCanvas and ScaledTextBox
import wx
print(wx.version())
import wx.lib
from wx.lib.floatcanvas import NavCanvas
app = wx.App(0)
wx.InitAllImageHandlers()
frame_1 = wx.Frame(None, wx.ID_ANY, "")
app.SetTopWindow(frame_1)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="""
I never freaking remember argparse syntax and the docs are so all over the place
that I need this for an example.
@bryan-lott
bryan-lott / Default (Windows).sublime-keymap
Last active June 21, 2016 15:01
Sublime Text Settings
[
{ "keys": ["ctrl+,"], "command": "jump_back" },
{ "keys": ["ctrl+."], "command": "jump_forward" },
{ "keys": ["ctrl+o"], "command": "fuzzy_start_from_file" },
{ "keys": ["ctrl+shift+o"], "command": "fuzzy_bookmarks_load" },
{ "keys": ["f5"], "command": "revert_file"}
]
@bryan-lott
bryan-lott / user.keymap
Last active August 27, 2016 14:16
Lighttable user.keymap file
;; User keymap
;; -----------------------------
;; Modify this file to add and subtract keybindings (keyboard shortcuts).
;; Keybindings allow custom keys to invoke any desired LightTable functionality that is behind a command.
;; A keybinding has the following format:
;;
;; [:TAG "KEYS" :COMMAND]
;;
;; * A tag indicates in what context the keybinding applies. Common tags are :app and :editor which respectively
;; indicate the keybinding can be used anywhere and the keybinding can only be used when editing text.