Skip to content

Instantly share code, notes, and snippets.

@apackeer
apackeer / why.sh
Created October 2, 2017 22:16 — forked from xiongchiamiov/why.sh
Use this when Amazon gives you an "Encoded authorization failure message" and you need to turn it into something readable. If you only get a request id... you're out of luck.
function decode-authorization-failure-message {
if [ $# -ne 1 ] || [ "$1" = -h ] || [ "$1" = --help ]; then
cat <<'EOT'
Usage: decode-authorization-failure-message <message>
Use this when Amazon gives you an "Encoded authorization failure message" and
you need to turn it into something readable.
EOT
return 1
fi
@apackeer
apackeer / JGroupsHibernateAWS.md
Created May 29, 2017 22:15 — forked from kenwdelong/JGroupsHibernateAWS.md
Using JGroups for Hibernate Second-Level Cache in AWS EC2

Configuring a Hibernate second-level cache in AWS is something of a challenge, as the EhCache multicast discovery mechanism doesn't work there. JGroups is another option, but can be difficult to configure. Here's how I got it working.

I'm using the very nice JGroups-AWS project https://github.com/meltmedia/jgroups-aws. In my configuration, you can see that I use "tags=Env,Role". This means that any given server will query EC2 to find out the values of those tags for itself. For example, suppose the server wakes up and finds that it has Env=Production and Role=API_Server. It will look for other servers with the same tag values (using the AWS webservice endpoints) and form a cluster with them. It checks back periodically so that if servers enter or leave the group it will adjust periodically. Very nice.

The 1.3.0 jgroups-aws uses JGroups 3.1.0, which is a bit out of date. I have not tried forcing a later version in the POM yet. I also cannot completely vouch for all the protocols set up in the ehcache.

@apackeer
apackeer / fullnode.md
Created March 5, 2017 09:46 — forked from romanz/fullnode.md
Bitcoin Full Node on AWS Free Tier

Bitcoin Full Node on AWS Free Tier

Provisioning

  • Launch one T2 micro instance, using Ubuntu 14.04 LTS AMI.
  • Open SSH and Bitcoin Protocol TCP ports: 22, 8333.
  • Attach 40GB EBS (General-Purpose SSD) volume for blockchain storage to /dev/sdf.

The pricing should be ~3$ for the first year (assuming 30GB upload per month). See here for more details.

@apackeer
apackeer / CloningEdisonPart2.md
Created September 20, 2016 05:47 — forked from sxing/CloningEdisonPart2.md
Got problems with CloningEdisons.md? This is the path I take when things don't work out for some reason.

I'm guessing you've had some problems with the other CloningEdisons instructions (https://gist.github.com/sxing/f02a4a1703b16803a7d4) if you're here. Sorry about that...

This is the path I take when things don't work out, usually related to a completely messed up data corruption that was my fault.

  1. Acquire a microSD card and an Edison breakout that has an microSD card slot, like the Arduino Expansion board. Make sure the microSD card is at least 4GBs in size.
  2. Make sure nothing that needs to be copied over is in your /home folder. This won't be copied over in the process.
  3. Follow these instructions to set up the Edison you want to clone to boot from USB: https://communities.intel.com/thread/61048
  4. Boot to the microSD card.
  5. Make a ext4 image that is the same size as your / partition. If you've already made an image, I recommend not recreating a new image and skip this step to save some time. This gets me pretty close in size without being larger:
@apackeer
apackeer / CloningEdisons.md
Created September 19, 2016 22:53 — forked from sxing/CloningEdisons.md
Cloning Edisons by making a flashable image from an existing Edison

This’ll make a flashable clone of an existing Intel Edison (with Yocto... Ubilinux here: https://gist.github.com/sxing/300b8a58c9f438fcc581). I've wanted to extract a flashable image from my Edisons for a while; I usually hack straight on my Edison until something works and don't want to porting to the Yocto build process afterwards. To clone Edisons, I've been using rubidium's commands from the Intel forums, but I wanted a method that worked on top of the Phone Flash Tool used for flashing Edison since it'll be easier to distribute images. I've tested this for flashing Edisons from ww36 (1.0), ww05-2015 (2.0), and ww25.5-2015 (2.1) firmwares to an ww25.5-2015 (2.1) based clone image.

NOTE: I've noticed that this doesn't work well with Edisons that are cloned copies that were produced through copying the entire mmcblk0 block as done in the Intel forum thread referenced above. I've built a workaround for that, but it is a bit longer: https://gist.github.c

@apackeer
apackeer / server.py
Created September 1, 2016 06:53 — forked from martijnvermaat/server.py
SimpleHTTPServer with history API fallback
#!/usr/bin/env python
"""
Modification of `python -m SimpleHTTPServer` with a fallback to /index.html
on requests for non-existing files.
This is useful when serving a static single page application using the HTML5
history API.
"""
{
"Version": "2012-10-17",
"Statement": [{
"Action": "ec2:*",
"Effect": "Allow",
"Resource": "*",
"Condition": {
"StringEquals": {
"ec2:Region": [
"us-east-1",
import React from 'react'
const provideContext = (contextKey, contextType) => (
React.createClass({
childContextTypes: {
[contextKey]: contextType
},
getChildContext() {
const { children, ...props } = this.props
@apackeer
apackeer / step1.py
Last active July 12, 2018 19:03
Lambda Dynamo Demo
from __future__ import print_function # Python 2/3 compatibility
import boto3
import json
import decimal
import time
# Helper class to convert a DynamoDB item to JSON.
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
@apackeer
apackeer / lambda-dynamo
Created July 13, 2016 01:12 — forked from markusklems/lambda-dynamo
Short aws lambda sample program that puts an item into dynamodb
// create an IAM Lambda role with access to dynamodb
// Launch Lambda in the same region as your dynamodb region
// (here: us-east-1)
// dynamodb table with hash key = user and range key = datetime
console.log('Loading event');
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
exports.handler = function(event, context) {