Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / npf.conf
Created March 30, 2017 03:09
Example npf config to redirect ports 80/443 to unprivileged ports
$ext_if = "vioif0"
$ext_v4 = inet4(vioif0)
map $ext_if dynamic XXX.XXX.XXX.XXX port 8080 <- $ext_v4 port 80
map $ext_if dynamic XXX.XXX.XXX.XXX port 4443 <- $ext_v4 port 443
group default {
pass final on lo0 all
pass final on $ext_if all
}
@travispaul
travispaul / bbb.md
Created May 1, 2017 15:03
Networking config for Beaglebone Black
# ifconfig
lo0: flags=0x8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33180
        inet6 ::1/128 flags 0x20<NODAD>
        inet6 fe80::1%lo0/64 flags 0x0 scopeid 0x1
        inet 127.0.0.1/8 flags 0x0
cpsw0: flags=0x8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        address: c8:a0:30:aa:65:c4
        media: Ethernet autoselect (100baseTX full-duplex)
 status: active
@travispaul
travispaul / cowsay9k.js
Created July 13, 2017 11:03
Cowsay test bot for MatterMost outgoing webhook
// https://docs.mattermost.com/developer/webhooks-outgoing.html
var express = require('express');
var cowsay = require('cowsay');
var bodyparser = require('body-parser');
var app = express();
app.use(bodyparser.urlencoded({ extended: true }));
app.get('/', function (req, res) {
res.end('<pre>'+ cowsay.say({text: 'Moo'}) + '</pre>');
@travispaul
travispaul / copycommit.sh
Created October 2, 2017 17:37
Alias for copying commits between forks
copycommit () {
if [ $# -lt 2 ]; then
echo -e "Usage:\n copycommit /path/to/repo commithash1 commithash2 ..."
return 1
fi
repo="$1/.git"
shift 1
if [ ! -d "$repo" ]; then
echo "$repo is not a git repo"
return 1
@travispaul
travispaul / answer.md
Last active January 26, 2018 12:43
module.exports how to return a function value?

The return value of getAOLDataCount is undefined. You're returning the aolCount variable from within an anonymous function in your .then() call and it's not being returned.

It's basically the same as this:

module.exports = {
    getAOLDataCount:  function () {
        wd = new WeeklyData(sequelize, Sequelize.DataTypes);
        wd.count({where: {week:201740, project: 8}}).then(function (aolCount) {
            console.log(aolCount);

return aolCount;