Skip to content

Instantly share code, notes, and snippets.

View seedifferently's full-sized avatar

Seth Davis seedifferently

View GitHub Profile
@seedifferently
seedifferently / Amazon_SES.py
Created February 1, 2011 19:34
Simple example email wrapper for Boto's SES
"""
Example code for sending emails using boto's SES module. Its main purpose is to
show how easy it is to build multipart text/html emails.
Unfortunately, at this time Amazon's SES doesn't seem to allow you to add
attachments to messages, but if it does in the future it would probably look
like the code that I've commented out below the exception.
The SES module of the Boto package isn't quite finalized yet, but I currently
have this code running using Harry Marr's implementation which is available at:
@seedifferently
seedifferently / sshid3.rb
Created December 23, 2011 00:31
Read ID3 info over SSH via Ruby
require 'net/sftp'
require 'mp3info'
require 'stringio'
io = StringIO.new
Net::SFTP.start('host.com', 'username', :password => 'password', :port => 22) do |sftp|
f = sftp.file.open("/path/to/file.mp3", "r")
begin
@seedifferently
seedifferently / api_error_message_directive.coffee
Created October 27, 2014 15:57
AngularJS API Error Message directive
angular.module 'app'
.directive 'apiErrorMessage', ->
dir = {}
dir.restrict = 'A'
dir.scope =
field: '=apiErrorMessage'
dir.priority = 100
dir.transclude = true
@seedifferently
seedifferently / gowebserver.go
Created November 7, 2014 02:33
Example Go webserver with combined http and https support
package main
import (
"net/http"
"io"
"strconv"
)
func HelloServer(c http.ResponseWriter, req *http.Request) {
body := "Hello World\n"
@seedifferently
seedifferently / dict_ex.py
Last active June 15, 2017 13:13
Python dict examples
>>> # create an empty dict
>>> d = {}
>>> # set a key/value pair
>>> d['food'] = 'spam'
>>> # retrieve a value for the key
>>> d['food']
'spam'
>>> # remove a key/value pair
>>> del d['food']
@seedifferently
seedifferently / dict_keyerror_ex.py
Last active June 15, 2017 13:13
Python dict keyerror
>>> d['missing']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'missing'
@seedifferently
seedifferently / check_dict_key_ex.py
Last active June 14, 2017 17:13
Python dict check key
>>> d = {'food': 'spam'}
>>> 'food' in d
True
>>> 'missing' in d
False
>>> 'missing' not in d
True
@seedifferently
seedifferently / dict_get_ex.py
Last active June 14, 2017 14:53
Python dict get method
>>> print(d.get('food'))
spam
>>> print(d.get('missing'))
None
>>> print(d.get('missing', 'I did not find a key by that name!'))
I did not find a key by that name!
@seedifferently
seedifferently / ip_counter_dict_ex.py
Created June 14, 2017 14:44
Python ip counter dict example
# assuming "ip_counts" is our dict and "req.ip_address" is the requestor's IP address
if req.ip_address in ip_counts:
# increment the count
ip_counts[req.ip_address] += 1
else:
# set an initial count
ip_counts[req.ip_address] = 1
@seedifferently
seedifferently / ip_counter_dict_missing_ex.py
Last active June 14, 2017 17:22
Python ip counter dict __missing__ example
# define our custom counter dict
class IPCounter(dict):
def __missing__(self, key):
return 0
ip_counts = IPCounter()
# ...other code that handles the request...
# increment the value (if the key is missing its initial value will be 0)