Skip to content

Instantly share code, notes, and snippets.

View andrewsmedina's full-sized avatar

Andrews Medina andrewsmedina

View GitHub Profile
@andrewsmedina
andrewsmedina / postgres_queries_and_commands.sql
Created September 27, 2021 18:18 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@andrewsmedina
andrewsmedina / tmux.md
Created November 22, 2018 14:13 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@andrewsmedina
andrewsmedina / findLongRunningOp.js
Created May 16, 2018 01:52 — forked from kylemclaren/findLongRunningOp.js
Find and (safely) kill long running MongoDB ops
db.currentOp().inprog.forEach(
function(op) {
if(op.secs_running > 5) printjson(op);
}
)
@andrewsmedina
andrewsmedina / README.md
Created December 21, 2015 19:42 — forked from rantav/README.md
Find slow queries in mongo DB

A few show tricks to find slow queries in mongodb

Enable profiling

First, you have to enable profiling

> db.setProfilingLevel(1)

Now let it run for a while. It collects the slow queries ( > 100ms) into a capped collections, so queries go in and if it's full, old queries go out, so don't be surprised that it's a moving target...

#!/usr/bin/env python
import argparse
import json
import os
import urllib2
def get_envs(app_name):
resp = request("/apps/{}/env".format(app_name))
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
#!/usr/bin/env python
import pymongo, redis, os
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
REDIS_PORT = os.getenv('REDIS_PORT', 6379)
MONGO_HOST = os.getenv('MONGODB_HOST', 'localhost')
MONGO_PORT = os.getenv('MONGODB_PORT', 27017)
mongo = pymongo.MongoClient(MONGO_HOST, MONGO_PORT)
import redis, os
HOST = os.getenv("HOST", "localhost")
PORT = os.getenv("PORT", 6379)
r = redis.StrictRedis(host=HOST, port=PORT)
cnames_app = r.get("cname*")
for cname_app in cnames_app:
cname = r.get(cname_app)
#!/bin/bash
PREFIX=registry.cloud.tsuru.io/tsuru/
read command
for image in "$@"
do
echo "Generating $image... "
full_image=${PREFIX}${image}
id=`docker -H 127.0.0.1:4243 run -d $full_image $command`

Simple ambassador container

The Simple Ambassador Container (let's just call it the ambassador) is a reusable container which can be added to your stack to represent a remote service. Using an ambassador your application can discover remote services using docker's standard links features.

Usage

Example usage:

REDIS_REMOTE_IP=1.2.3.4