Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import sys
import argparse
from collections import defaultdict
from datetime import datetime,timedelta
import requests
import logging
import traceback
class JenkinsJobProfiler(object):
def container_id(pid)
  cgroup_file = "/proc/#{pid}/cgroup"
  return nil unless File.exist?(cgroup_file)

  container_id = File.foreach(cgroup_file)
    .map(&:strip)
    .select { |cg| cg.match?(/docker/) }.first
  container_id.split('/').last
end
#!/bin/bash
set -ex
source credentials.sh
export JENKINS_URL=http://127.0.0.1:8080
export NODE_NAME=foobar3
export JENKINS_CRUMB=$(curl --cookie-jar jenkins-cookies -s -X GET $JENKINS_URL/crumbIssuer/api/json --user ${JENKINS_USERNAME}:${JENKINS_PASSWORD} | jq -r '.crumb')
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <dlfcn.h>
#include <asm-generic/errno-base.h>
#include <errno.h>
@gagomes
gagomes / scan-and-copy-all-images.py
Last active January 6, 2018 11:07
scan pictures in a given path and copy them out onto another
#!/usr/bin/python
# I used this script to scan pictures in a 15 year old
# windows hard-drive and copy them to a specific folder with a name
# based on an increasing sequence. It also seemed to pick multiple
# formats that weren't exactly the type of pictures I would care about,
# so I filtered for those (icons, bitmaps, etc)
#
import sys
import os
@gagomes
gagomes / abown4.c
Created January 5, 2018 02:11
A no-bruteforce exploit against abo4 from the "Advanced Buffer Overflow" collection by Gera, written sometime circa 2002--2003
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <elf.h>
@gagomes
gagomes / regex_match.md
Last active September 19, 2017 07:45
Rough translation of the C version of the regex parser by Brian Kernighan from chapter 1 of "Beautiful Code" to Python
#!/usr/bin/env python
#
# Harsh translation from C to Python, with minimal python idioms.
# Original code by Brian Kernighan in chapter 1 of Beautiful Code
#
def match(regstr, s):
'''match: search for regexp anywhere in text'''
if regstr.startswith('^'):
return matchhere(regstr[1:], s)

MySQL

list all tables from all databases (Taken from a SO post)

SELECT table_name, table_schema AS dbname FROM INFORMATION_SCHEMA.TABLES
@gagomes
gagomes / chef-one-liners.md
Last active January 24, 2017 12:00
chef-one-liners

Get a list of nodes and their runlists matching a given recipe

knife exec -E 'nodes.find("recipe:*elasticsearch*") { |n| puts "hostname: #{n.name} runlist: #{n.run_list}" }'

@gagomes
gagomes / single-docker-instance.sh
Created January 9, 2017 00:20
single docker instance
#!/bin/bash
NAME=rpmfs
CONTAINER=$(docker ps -q -a --filter name=$NAME)
if test -z "$CONTAINER"; then
docker run --name=$NAME \
-v ${PWD}/../centos/:/data/centos \
-v ${PWD}/../linux:/data/linux \
-v images:/data/images \