Skip to content

Instantly share code, notes, and snippets.

View jlafon's full-sized avatar

Jharrod LaFon jlafon

View GitHub Profile
@jlafon
jlafon / dynamodb.md
Created December 3, 2014 05:03
An Introduction to Amazon's DynamoDB

An introduction to DynamoDB

DynamoDB is a powerful, fully managed, low latency, NoSQL database service provided by Amazon. DynamoDB allows you to pay for dedicated throughput, with predictable performance for "any level of request traffic". Scalability is handled for you, and data is replicated across multiple availability zones automatically. Amazon handles all of the pain points associated with managing a distributed datastore for you, including replication, load balancing, provisioning, and backups. All that is left is for you to take your data, and its access patterns, and make it work in the denormalized world of NoSQL.

Modeling your data

The single most important part of using DynamoDB begins before you ever put data into it: designing the table(s) and keys. Keys (Amazon calls them primary keys) can be composed of one attribute, called a hash key, or a compound key called the hash and range key. The key is used to uniquely identify an item in a table. The choice of the primary key is particularl

@jlafon
jlafon / issue_25.py
Last active August 29, 2015 14:01
Issue 25 example
import random
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute, NumberAttribute
from pynamodb.indexes import LocalSecondaryIndex, AllProjection
class ViewIndex(LocalSecondaryIndex):
"""
This class represents a local secondary index
"""
@jlafon
jlafon / default_vals.py
Created May 21, 2014 14:31
Default attribute values
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute
def make_id():
return somerandomid
class Thread(Model):
table_name = 'Thread'
forum_name = UnicodeAttribute(hash_key=True)
from __future__ import print_function
import logging
from pynamodb.models import Model
from pynamodb.attributes import (UnicodeAttribute)
logging.basicConfig()
log = logging.getLogger("")
log.setLevel(logging.DEBUG)
log.propagate = True
@jlafon
jlafon / keybase.md
Created March 27, 2014 17:15
Keybase proof

Keybase proof

I hereby claim:

  • I am jlafon on github.
  • I am jlafon (https://keybase.io/jlafon) on keybase.
  • I have a public key whose fingerprint is 852D 73C3 9990 1540 B38C DE44 8D70 F113 3806 3D18

To claim this, I am signing this object:

@jlafon
jlafon / .gitconfig
Created March 26, 2014 13:11
My git aliases
[alias]
# View abbreviated SHA, description, and history graph of the latest 20 commits
l = log --pretty=oneline -n 20 --graph --abbrev-commit
# View the current working tree status using the short format
s = status -s
# Show the diff between the latest commit and the current state
d = !"git diff-index --quiet HEAD -- || clear; git --no-pager diff --patch-with-stat"
@jlafon
jlafon / pynamodb_large_item.py
Created March 21, 2014 01:24
A PynamoDB example for items larger than 64k.
from pynamodb.models import Model
from pynamodb.attributes import (
UnicodeAttribute, NumberAttribute
)
class Thread(Model):
table_name = "Thread"
forum_name = UnicodeAttribute(hash_key=True)
subject = UnicodeAttribute(range_key=True)
@jlafon
jlafon / centralized.csv
Last active January 2, 2016 08:19
Heatmap using D3 with legend.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Sender Receiver Bytes
0 0 0
0 1 1416764092
0 2 4098253320
0 3 2106916386
0 4 1262617412
0 5 1059002706
0 6 891019678
0 7 719843912
0 8 794784178
@jlafon
jlafon / git-segfault.patch
Created August 16, 2013 02:03
git patch for submodule seg fault
Here is an example .gitmodules that will cause a segmentation fault:
[submodule "foo-module"]
path
url = http://host/repo.git
$ git status
Segmentation fault (core dumped)
This occurs because in the function parse_submodule_config_option, the
variable 'value' is assumed not to be null, and when passed as an
@jlafon
jlafon / gist:6030948
Created July 18, 2013 16:55
Stack trace from elasticluster
$ mkvirtualenv elasticluster
(elasticluster) $ pip install elasticluster
...
(elasticluster) $ elasticluster list
WARNING:gc3.elasticluster:Deploying default configuration file to /Users/jlafon/.elasticluster/config.
Traceback (most recent call last):
File "/Users/jlafon/.virtualenv/elasticluster/bin/elasticluster", line 8, in <module>
load_entry_point('elasticluster==1.0.0', 'console_scripts', 'elasticluster')()
File "/Users/jlafon/.virtualenv/elasticluster/lib/python2.7/site-packages/elasticluster/main.py", line 152, in main
app.run()