Skip to content

Instantly share code, notes, and snippets.

@travispaul
travispaul / mtest.c
Last active December 15, 2016 23:12
mmap /dev/mmem0.0c test
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
int
main(int argc, char **argv)
@travispaul
travispaul / cloudapi-getusers.sh
Last active November 15, 2016 14:11
Get users from CloudAPI using cURL
# Update these if your ssh keys exist in another location:
sshkey=~/.ssh/id_rsa
sshpub=${sshkey}.pub
now=$(date -u "+%a, %d %h %Y %H:%M:%S GMT");
signature=$(echo ${now} | tr -d '\n' | openssl dgst -sha256 -sign $sshkey | openssl enc -e -a | tr -d '\n');
fingerprint=$(ssh-keygen -l -E md5 -f $sshpub | awk '{print $2}' | sed -e 's/MD5://')
curl -i -H "Accept: application/json" -H "accept-version: ~8" -H "Date: ${now}" -H "Authorization: Signature keyId=\"/$SDC_ACCOUNT/keys/${fingerprint}\",algorithm=\"rsa-sha256\" ${signature}" --url $SDC_URL/$SDC_ACCOUNT/users;
@travispaul
travispaul / manta-rbac-write-only.md
Last active November 15, 2016 00:24
Manta Write-only RBAC example

SubUser account with write-only permissions for directory

Useful for logs, backups, etc where it may not be desirable for the client to read files it has uploaded or other files within the upload directory.

Example policy and role for subuser:

$ sdc-policy create --name WriteOnly --rules "can putobject"
$ sdc-role create --name LogWriter --default-members mysubuser --members mysubuser --policies WriteOnly
@travispaul
travispaul / timertest.c
Created November 8, 2016 15:20
Create timers (until you can't)
// Example:
// cc -lrt timertest.c
// ./a.out 128
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
int
@travispaul
travispaul / memcaptest.c
Last active November 8, 2016 14:38
Eat up memory (for testing memory caps)
// example: ./a.out 10 1 150
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv) {
int mbytes = atoi(argv[1]);
int seconds = atoi(argv[2]);
int limit = atoi(argv[3]);
int total = 0;
@travispaul
travispaul / 31-couchdb.sh
Last active October 3, 2016 15:23
Pid file is created before CouchDB is able to respond to HTTP requests.
# Get couchdb_password from metadata if exists, or use couchdb_pw, or set one.
log "getting couchdb_password"
if [[ $(mdata-get couchdb_password &>/dev/null)$? -eq "0" ]]; then
COUCHDB_PW=$(mdata-get couchdb_password 2>/dev/null);
mdata-put couchdb_pw ${COUCHDB_PW}
elif [[ $(mdata-get couchdb_pw &>/dev/null)$? -eq "0" ]]; then
COUCHDB_PW=$(mdata-get couchdb_pw 2>/dev/null);
else
COUCHDB_PW=$(od -An -N8 -x /dev/random | head -1 | tr -d ' ');
mdata-put couchdb_pw ${COUCHDB_PW}
@travispaul
travispaul / mget.php
Created September 19, 2016 16:29
php-manta test
tpaul@mba:/Users/tpaul/Code/php-manta/examples
$ mget ~~/
{"name":"jobs","type":"directory","mtime":"2013-05-22T17:39:43.714Z"}
{"name":"public","type":"directory","mtime":"2013-05-22T17:39:43.714Z"}
{"name":"reports","type":"directory","mtime":"2013-05-22T17:39:43.714Z"}
{"name":"stor","type":"directory","mtime":"2013-05-22T17:39:43.714Z"}
tpaul@mba:/Users/tpaul/Code/php-manta/examples
$ php mget.php ~~/
PHP Warning: openssl_sign(): supplied key param cannot be coerced into a private key in /Users/tpaul/Code/php-manta/src/MantaClient.php on line 372
@travispaul
travispaul / salt.patch
Created February 7, 2016 23:37
Update salt to 2015.8.5
Index: Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/salt/Makefile,v
retrieving revision 1.34
diff -u -r1.34 Makefile
--- Makefile 4 Feb 2016 22:05:36 -0000 1.34
+++ Makefile 7 Feb 2016 23:33:54 -0000
@@ -1,7 +1,6 @@
# $NetBSD: Makefile,v 1.34 2016/02/04 22:05:36 khorben Exp $
@travispaul
travispaul / pthread.c
Created February 7, 2016 20:59
pthread test
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
void *perform_work(void *argument)
{
int passed_in_value;
@travispaul
travispaul / salt.patch
Created December 16, 2015 23:32
salt.patch
commit ba76062950095850ec165be0be3584624da2046f
Author: Travis Paul <Tr@validusa.com>
Date: Wed Dec 16 23:20:36 2015 +0000
sysutils/salt: Fix cron module for SmartOS
Upstream PR sent: https://github.com/saltstack/salt/pull/29777
diff --git a/sysutils/salt/Makefile b/sysutils/salt/Makefile
index 2cd7c5a..67cdc71 100644