Skip to content

Instantly share code, notes, and snippets.

We keep all our Terraform files under the terraform directory.

Terraform allows to reuse definitions across environments. We thus don't have to have a set of definitions for provisioning Onadata resources in the production environment and a different set of definitions for provisioning Onadata resources in the staging environment. How we go about this is by creating a shared Terraform module for our setup, then including this module in Terraform files corresponding to each of the environments we plan to deploy the setup.

The following subsections will take you through how to codify your setup using Terraform, the Ona way. As a reference, we will use Onadata's Terraform files:

1. Create a Reusable Module

Keep the Terraform resource blocks for your setup in ../terraform/modules/. For instance, the Onadata setup's resource blocks are kept in terraform/modules/onadata. Then isolate the Ter

1. Determine how to make the connection
Most serial devices can be accessed via a serial RS-232 cable. However, most computers these days don't have this port.
The [RFC2217](http://blog.philippklaus.de/2011/08/make-rs232-serial-devices-accessible-via-ethernet/) protocol with the help of an RJ45 to RS-232 cable should do the trick.
There are several tools you can use to initiate contact once connected:
- YPort: Part of the opensource ethersex firmware
- ser2net: Nice serial to network proxy that is still kept up to date
- socat: socat STDIO:/dev/ttyS0,nonblock,raw,echo=0 TCP-LISTEN:1234
#!/bin/bash
# Initiates the process of renewing AWS sessions for when you need to
# use MFA authentication with the AWS CLI (or any tool that relies on the
# AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN env vars).
# The script assumes Python3 is installed.
#
# This script expects the following variables have been exported and
# are avilable to it:
# 1. AWS_IAM_MFA_DEVICE_ARN

How to move commits between two repos that don't share a commit history:

  • I have two repos github.com/<my employer>/playbooks and github.com/roots/trellis
  • github.com/<my employer>/playbooks has a directory wordpress/trellis
  • wordpress/trellis in github.com/<my employer>/playbooks contains code from github.com/roots/trellis, has changes made but commited in github.com/<my employer>/playbooks/.git all tracked changes from upstream have been lost (github.com/<my employer>/playbooks/wordpress/trellis/.git was deleted).

We need to merge the latest changes in github.com/roots/trellis with whatever changes we staged for github.com/<my employer>/playbooks/wordpress/trellis

  1. Clone git@github.com:roots/trellis.git
git clone git@github.com:roots/trellis.git
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
int main() {
int res;
res = sethostid(gethostid());
if (res != 0) {
switch (errno) {
case EACCES:
#!/bin/bash
echo "Enter the serial number for the device you want to switch to WiFi"
read serialNo
ipAddr=`adb -s ${serialNo} shell ifconfig wlan0 | sed -n 's/inet addr:\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/p'`
if [ -z "${ipAddr}" ]; then
ipAddr=`adb -s ${serialNo} shell netcfg | sed -n 's/wlan0[ ]*UP[ ]*\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/p'`
fi

Keybase proof

I hereby claim:

  • I am jasonrogena on github.
  • I am jasonrogena (https://keybase.io/jasonrogena) on keybase.
  • I have a public key whose fingerprint is FE16 05CD 2F20 E5DE 1CA2 B1F2 DB04 2D01 3212 3B07

To claim this, I am signing this object:

smsManager.sendMultipartTextMessage(SMS_SERVER_ADDRESS, null, multipartMessage, sentPendingIntents, deliveredPendingIntents);
long startTime = System.currentTimeMillis();
if(waitForResponse){
while(true){
long currTime = System.currentTimeMillis();
long timeDiff = currTime - startTime;
if(getSharedPreference(context, SP_KEY_SMS_RESPONSE,"").length()>0){
return getSharedPreference(context, SP_KEY_SMS_RESPONSE,"");
}
//register a new sent and delivered intent for each of the parts
ArrayList<PendingIntent> sentPendingIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveredPendingIntents = new ArrayList<PendingIntent>();
for(int i = 0; i<noOfParts; i++){
PendingIntent newSentPE = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_SMS_SENT), 0);
sentPendingIntents.add(newSentPE);
PendingIntent newDeliveredPE = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_SMS_DELIVERED), 0);
deliveredPendingIntents.add(newDeliveredPE);
}