Skip to content

Instantly share code, notes, and snippets.

@pfigue
pfigue / keybase.md
Created December 15, 2015 23:39
Keybase Github Proving

Keybase proof

I hereby claim:

  • I am pfigue on github.
  • I am pfigue (https://keybase.io/pfigue) on keybase.
  • I have a public key ASC7-O8ssdK2kWqGAcI0Ysyi2BWzWYSy_iEmBOY1UegLzgo

To claim this, I am signing this object:

@pfigue
pfigue / cap1.c
Created November 3, 2015 09:24
Decodes a /proc/PID/status capabilities mask.
/*
* Compile just with `gcc -o cap1 cap1.c`
*/
#include <stdio.h>
#include <stdlib.h>
char *get_cap_name(unsigned short cap_index)
@pfigue
pfigue / eatmem.c
Created October 7, 2015 11:39
Eat Memory. In C. For testing memory limits.
// Compile with e.g. `gcc -o /tmp/eatmem /tmp/eatmem.c`
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char **argv)
{
void *p, *end, *cur;
size_t megs;
@pfigue
pfigue / curl-cheatsheet.md
Last active August 28, 2015 09:34
curl cheatsheet

--config

-I shows received headers

-L follows links for 30x redirections

--resolve a.b.c:80:1.2.3.4 resolves domain name a.b.c to 1.2.3.4.

@pfigue
pfigue / clock_gettime.c
Created April 23, 2015 07:54
Example of using libC clock_gettime() and clock_getres() functions.
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv)
{
int result;
struct timespec tp;
clockid_t clk_id;
@pfigue
pfigue / clock.c
Created April 23, 2015 07:00
Example of using libC clock() function.
/*
*
* Compile with: `gcc -o clock clock.c`
*
* [clock(3) - Linux man page](http://linux.die.net/man/3/clock): *The value returned is the CPU time used [by the process] so far[...]*
* [What’s the correct way to use printf to print a clock_t?](http://stackoverflow.com/questions/1083142/what-s-the-correct-way-to-use-printf-to-print-a-clock-t)
*
*/
#include <stdio.h>
@pfigue
pfigue / apt_dpkg_cheatsheet.md
Created March 18, 2015 13:51
Ubuntu: apt/dpkg cheathseet

Prevent a package to be upgraded using apt-get upgrade:

apt-mark [hold|unhold] pkg_name

@pfigue
pfigue / perl_ol_cli.md
Created March 18, 2015 12:44
Perl one-liners for the command line

Taking groups inside of a line

From a bunch of lines like Conf e2fslibs (1.42.9-3ubuntu1.2 Ubuntu:14.04/trusty-updates [amd64]) [e2fsprogs:amd64 ] I want to get e2fslibs. apt-get upgrade --dry-run gives such kind of lines.

perl -pe 's/^Conf\s(\S+)\s.*$/$1/'

@pfigue
pfigue / docker_cheatsheet.md
Last active August 29, 2015 14:16
Docker Cheatsheet

List of Docker containers

docker ps  # shows running containers
docker ps --all  # shows all installed containers

SSH into Docker container

docker attach 665b4a1e17b6/image-name

Pulling a docker image from Docker Hub

@pfigue
pfigue / set_limit_nofile.c
Created March 6, 2015 14:43
Using setlimit() system call to change limit of FD for a process. Copied from http://lzone.de/Debian%20Ubuntu%20ulimit%20Check%20List
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/resource.h>
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
} while (0)