Skip to content

Instantly share code, notes, and snippets.

View shared-terraform-files-different-envs.md

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/<Name of setup>. For instance, the Onadata setup's resource blocks are kept in terraform/modules/onadata. Then isolate the Ter

View gethostid.c
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
int main() {
int res;
res = sethostid(gethostid());
if (res != 0) {
switch (errno) {
case EACCES:
View adb_wifi_switch.sh
#!/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
View keybase.md

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:

View mysql_debconf_module.yml
---
#- name: Copy the MariaDB root non-interactive password
# template: src=mariadb_non_interactive_password.sh.j2 dest=/tmp/mariadb_non_interactive_password.sh owner=root group=root mode=0700
#
#- name: Execute the MariaDB root non-interactive password file
# shell: /tmp/mariadb_non_interactive_password.sh
#
#- name: Delete the MariaDB non-interactive password file
# file: path=/tmp/mariadb_non_interactive_password.sh state=absent
- name: Set Debconf root_password
View mysql.yml
---
- name: Copy the MariaDB root non-interactive password
template: src=mariadb_non_interactive_password.sh.j2 dest=/tmp/mariadb_non_interactive_password.sh owner=root group=root mode=0700
- name: Execute the MariaDN root non-interactive password file
shell: /tmp/mariadb_non_interactive_password.sh
- name: Delete the non-interactive password file
file: path=/tmp/mariadb_non_interactive_password.sh state=absent
View mariadb_non-interactive_password_ansible.sh
#! /bin/bash
export DEBIAN_FRONTEND=noninteractive
debconf-set-selections <<< 'mariadb-server mysql-server/root_password password {{ mariadb_root_password }}'
debconf-set-selections <<< 'mariadb-server mysql-server/root_password_again password {{ mariadb_root_password }}'
View Reverse engineering a serial protocol
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
View sendMultipartMessage
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,"");
}
You can’t perform that action at this time.