Skip to content

Instantly share code, notes, and snippets.

View freyes's full-sized avatar
🥑

Felipe Reyes freyes

🥑
View GitHub Profile
@freyes
freyes / query-etcd.sh
Last active November 30, 2020 20:58 — forked from brettmilford/query-etcd.sh
Query etcd keys
#!/bin/bash -eux
# brettmilford: added etcd /metrics gathering
# This file is based on https://code.launchpad.net/~freyes/+git/experiment
# Modified to use xargs instead of parallel
# 'etcd.etcdctl' is provided by the etcd snap
which etcd.etcdctl
PARALLEL_REQS=20
dialmgo() {
agent=$(cd /var/lib/juju/agents; echo machine-*)
pw=$(sudo cat /var/lib/juju/agents/${agent}/agent.conf |grep statepassword |awk '{ print $2 }')
mongo --ssl --sslAllowInvalidCertificates -u ${agent} -p $pw localhost:37017/juju --authenticationDatabase admin
}
@freyes
freyes / mongodb_collection_sizes.js
Last active July 23, 2020 14:28 — forked from joeyAghion/mongodb_collection_sizes.js
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
# for juju on xenial
cat << EOF > /tmp/a.js
db = db.getSiblingDB('juju');
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
EOF
/usr/lib/juju/mongo3.2/bin/mongo --sslAllowInvalidCertificates --ssl -u admin -p $(grep oldpassword /var/lib/juju/agents/machine-0/agent.conf | awk -e '{print $2}') localhost:37017/admin /tmp/a.js
@freyes
freyes / git-on-lp.md
Created July 18, 2018 16:12 — forked from anjohnson/git-on-lp.md
Notes for Git on Launchpad

Andrew's Notes on using Git with Launchpad

This page describes how I'm planning to work with git and lp, others don't have to follow my approach. The mirroring that I describe below may be slightly unusual, so your local git expert might not fully understand it.

Getting Started

Configure the lp: prefix in ~/.gitconfig

[url "git+ssh://anj@git.launchpad.net/"]
    insteadof = lp:
package main
import (
"fmt"
"os"
"github.com/juju/utils"
)
const MIN_LEN = 30
package main
import (
"fmt"
"os"
"github.com/juju/utils"
)
const MIN_LEN = 30
@freyes
freyes / MongoDB update all matching.js
Created August 23, 2016 19:50 — forked from sym3tri/MongoDB update all matching.js
How to update a single field in a MongoDB collection for all documents matching a specific criteria
// FROM: http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29
//
// db.collection.update( criteria, objNew, upsert, multi )
// criteria - query which selects the record to update;
// objNew - updated object or $ operators (e.g., $inc) which manipulate the object
// upsert - if this should be an "upsert"; that is, if the record does not exist, insert it
// multi - if all documents matching criteria should be updated
//
// SQL VERSION:
// UPDATE myTable SET dateField = '2011-01-01' WHERE condField = 'condValue'
@freyes
freyes / mongo.sh
Last active March 27, 2024 18:25 — forked from niedbalski/mongo.sh
Connect to Juju 2.0 Mongodb
# valid for juju 2.0
# see https://bugs.launchpad.net/ubuntu/+source/juju-mongodb3.2/+bug/1583740
$ juju ssh -m controller 0
# when running a Xenial controller
/usr/lib/juju/mongo3.2/bin/mongo --sslAllowInvalidCertificates --ssl -u admin -p $(grep oldpassword /var/lib/juju/agents/machine-0/agent.conf | awk -e '{print $2}') localhost:37017/admin
# when running a Bionic controller
mongo --sslAllowInvalidCertificates --ssl -u admin -p $(grep oldpassword /var/lib/juju/agents/machine-0/agent.conf | awk -e '{print $2}') localhost:37017/admin
@freyes
freyes / cmadison.py
Created May 12, 2016 19:18 — forked from wolsen/cmadison.py
rmadison + cloud-archive madison
#!/usr/bin/env python
#
# Provides a rather basic version of rmadison (or dak ls if you prefer)
# for the Ubuntu cloud-archive.
#
# This script works in the following manner:
# 1) It will show the rmadison output for the selected package to show
# the values of packages within the main ubuntu archives
# 2) It will show similar output for the selected package in the ubuntu
# cloud archives.
@freyes
freyes / auth.py
Created January 6, 2016 21:28 — forked from niedbalski/auth.py
hmac-encrypt-request
from Crypto.Hash import HMAC
from Crypto.Hash import SHA
import hashlib
import datetime
class Auth:
@classmethod
def sign(cls, method, c_type, body, uri, key=None):