Skip to content

Instantly share code, notes, and snippets.

@enaeseth
enaeseth / yaml_ordered_dict.py
Created February 25, 2011 19:54
Load YAML mappings as ordered dictionaries
import yaml
import yaml.constructor
try:
# included in standard lib from Python 2.7
from collections import OrderedDict
except ImportError:
# try importing the backported drop-in replacement
# it's available on PyPI
from ordereddict import OrderedDict
@ykessler
ykessler / gae_handler.py
Created May 11, 2012 20:23
Python logging handlers
class GAEHandler(logging.Handler):
"""
Logging handler for GAE DataStore
"""
def emit(self, record):
from google.appengine.ext import db
class Log(db.Model):
name = db.StringProperty()
@rosner
rosner / app.py
Created November 23, 2012 09:17
Simple flask app with user login, registration based on twitters bootstrap
from flask import Flask, render_template
from flask.ext.security import SQLAlchemyUserDatastore, Security
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.bootstrap import Bootstrap
from flask_mail import Mail
from flask.ext.security import UserMixin, RoleMixin
app = Flask(__name__)
@larsyencken
larsyencken / sound_delay.py
Last active December 10, 2020 11:13
PyAudio: record sound and play it back after a delay
#
# sound_delay.py
#
"""
Record sound and play it back after a delay.
"""
import multiprocessing as mp
import time
@lrhache
lrhache / python-selenium-open-tab.md
Last active June 10, 2023 13:49
Python Selenium - Open new tab / focus tab / close tab

On a recent project, I ran into an issue with Python Selenium webdriver. There's no easy way to open a new tab, grab whatever you need and return to original window opener.

Here's a couple people who ran into the same complication:

So, after many minutes (read about an hour) of searching, I decided to do find a quick solution to this problem.

@mrkline
mrkline / c_sharp_for_python.md
Last active June 23, 2024 14:46
An intro to C# for a Python developer. Made for one of my coworkers.

C# For Python Programmers

Syntax and core concepts

Basic Syntax

  • Single-line comments are started with //. Multi-line comments are started with /* and ended with */.

  • C# uses braces ({ and }) instead of indentation to organize code into blocks. If a block is a single line, the braces can be omitted. For example,

@juhasch
juhasch / NotebookExtensionsManager.ipynb
Last active August 29, 2015 14:02
First draft of a Notebook helping with Notebook Extensions
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 19, 2024 18:04
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@mtearle
mtearle / EXAMPLE-socket.py
Created October 14, 2014 15:31
npyscreen EXAMPLE of a socket connection updating widgets
#!/usr/bin/env python
import npyscreen, curses
# Incorporates code
# from http://www.binarytides.com/python-socket-server-code-example/
# Socket server in python using select function
import socket, select
class MyTestApp(npyscreen.NPSAppManaged):
# socket code
@bollwyvl
bollwyvl / Embedded Mermaid diagrams in the IPython Notebook.ipynb
Last active January 17, 2023 10:12
Embedded Mermaid diagrams in the IPython Notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.