Skip to content

Instantly share code, notes, and snippets.

@yosemitebandit
yosemitebandit / pwm_stepper_control.ino
Last active November 23, 2023 19:00
controlling a stepper motor with PWM
/* Teensy LC sketch for controlling a stepper motor.
Reads comma-separate commands over serial. Sends back number of steps taken.
Commands are of the form:
step,300,800 -> stepper should move 300 sixteenth-steps forward at 800 steps per second
step,-124,100 -> stepper should move 124 sixteenth-steps backward at 100 steps per second
*/
@yosemitebandit
yosemitebandit / openpyxl-install-with-pip
Created June 4, 2012 17:42
reading xlsx files in python with openpyxl
$ pip install -E ~/conf/virtualenvs/xyuml https://bitbucket.org/ericgazoni/openpyxl/get/1.5.8.zip
@yosemitebandit
yosemitebandit / key-fingerprint
Created March 7, 2012 18:27
view your ssh public key's fingerprint; compare this to what Github has listed in the ssh key audit
$ ssh-keygen -l -f /path/to/keys/id_rsa.pub
2048 aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99 id_rsa.pub (RSA)
@yosemitebandit
yosemitebandit / send_pdf_with_boto_ses.py
Created June 6, 2012 17:56
send PDF attachment with boto and SES
''' quick example showing how to attach a pdf to multipart messages
and then send them from SES via boto
'''
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import boto
@yosemitebandit
yosemitebandit / tables.py
Created April 20, 2015 15:56
django tables 2 table with column header from db
class EventTable(tables.Table):
def __init__(self, *args, **kwargs):
# Pop out the date_header named arg before calling super.
date_header = kwargs.pop('date_header', 'Date')
super(EventTable, self).__init__(*args, **kwargs)
self.base_columns['date'].verbose_name = date_header
class Meta:
model = models.Event
fields = ('date', 'value')
@yosemitebandit
yosemitebandit / meduele_login_with_requests.py
Created February 12, 2012 02:46
using the request lib's sessions to login; bonus: beautiful soup finds the csrf token
#!/usr/bin/env python
'''
testing a login to meduele using sessions
meduele checks csrf tokens with every request, even during login
'''
import requests
from BeautifulSoup import BeautifulSoup
# need to capture a valid csrf token
# first visit the login page to generate one
@yosemitebandit
yosemitebandit / ncdc_processor.py
Created February 21, 2012 21:20
Format historical weather data exported from the NCDC
#!/usr/bin/env python
'''
ncdc_processor.py
imports a csv of historical weather data from the NCDC
exports a somewhat more sanely formatted csv suitable for graphing
data from http://www7.ncdc.noaa.gov/CDO/cdo
usage:
$ python ncdc_processor.py /path/to/ncdc_data.txt /path/to/export.csv
@yosemitebandit
yosemitebandit / order_by_ignoring_null.py
Last active August 18, 2021 21:34
an example of ordering a Django queryset while ignoring null values
"""Order a queryset by last_active and make null values sort last."""
import datetime
from django.db.models.functions import Coalesce
from app import models
# Coalesce works by taking the first non-null value. So we give it
@yosemitebandit
yosemitebandit / ibm_queue.py
Created August 17, 2011 23:28
IBM's python threading example with Queues
#!/usr/bin/python
# -*- coding: utf-8 -*-
import Queue
import threading
import urllib2
import time
hosts = ['http://yahoo.com', 'http://google.com', 'http://amazon.com',
'http://ibm.com', 'http://apple.com']
@yosemitebandit
yosemitebandit / xls_to_json.py
Created April 3, 2015 03:28
converting xls files to JSON dicts in python
"""XLS -> json converter
first:
$ pip install xlrd
then:
$ cat in.xls
date, temp, pressure
Jan 1, 73, 455
Jan 3, 72, 344