Skip to content

Instantly share code, notes, and snippets.

@stantona
stantona / template.yaml
Created February 19, 2020 20:47
Inherit Instance tags
UserData:
Fn::Base64: |
#!/bin/bash
AWS_AVAIL_ZONE="$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone)"
AWS_INSTANCE_ID="$(curl http://169.254.169.254/latest/meta-data/instance-id)"
AWS_REGION="$(echo "${AWS_AVAIL_ZONE}" | sed 's/[a-z]$//')"
VOLUME_IDS="$(aws ec2 describe-instances --region $AWS_REGION --instance-id $AWS_INSTANCE_ID --output text --query Reservations[0].Instances[0].BlockDeviceMappings[*].Ebs.VolumeId)"
for TAG_DEF in $(aws ec2 describe-tags --filter="Name=resource-id,Values=${AWS_INSTANCE_ID}" --region "${AWS_REGION}" | jq .'Tags | .[] | "Name=\(.Key),Value=\(.Value)"'); do
aws ec2 create-tags --dry-run --resources "${VOLUME_IDS//$'\t'/ }" --region "${AWS_REGION}" --tags "${TAG_DEF}"
@stantona
stantona / Pascal's Triangle
Last active August 29, 2015 14:01
I struggled to find a solution for Pascal's triangle in scheme.
(define (pascal-value row elem)
(cond ((= row 1) 1)
((= elem 1) 1)
((= row elem) 1)
(else (+ (pascal-value (- row 1) (- elem 1))
(pascal-value (- row 1) elem)))))
@stantona
stantona / 0_reuse_code.js
Created March 26, 2014 00:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#ifndef __dbg_h__
#define __dbg_h__
#include <stdio.h>
#include <errno.h>
#include <string.h>
#ifdef NDEBUG
#define debug(M, ...)
#else
#ifndef __dbg_h__
#define __dbg_h__
#include <stdio.h>
#include <errno.h>
#include <string.h>
#ifdef NDEBUG
#define debug(M, ...)
#else
#ifndef __dbg_h__
#define __dbg_h__
#include <stdio.h>
#include <errno.h>
#include <string.h>
#ifdef NDEBUG
#define debug(M, ...)
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void die(const char *message)
{
if(errno) {
perror(message);
} else {
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#define MAX_DATA 512
#define MAX_ROWS 100
struct Address {
-module(process_exc).
-export([start/1, proc/1]).
start(M) ->
N1 = spawn(process_exc, proc, [M]),
N2 = spawn(process_exc, proc, [M]),
N1 ! {N2, ping}.
proc(M) ->
proc(M, 0).
@stantona
stantona / ring.erl
Last active December 17, 2015 12:59
-module(ring).
-export([start/2, forward_to/1]).
start(Number, Iterations) ->
Pid = create_processes(Number-1),
Pid ! msg,
forward_to(Pid, Iterations, 0).
create_processes(Number) ->
io:format("spawning ~p processes...~n", [Number]),