Skip to content

Instantly share code, notes, and snippets.

@javiermon
javiermon / LICENSE
Last active May 5, 2024 05:15
get default gateway
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
@javiermon
javiermon / prename.pl
Created October 23, 2012 15:43
`prename` script from Debian's 'perl' package
#!/usr/bin/perl -w
#
# This script was developed by Robin Barker (Robin.Barker@npl.co.uk),
# from Larry Wall's original script eg/rename from the perl source.
#
# This script is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# Larry(?)'s RCS header:
# RCSfile: rename,v Revision: 4.1 Date: 92/08/07 17:20:30
@javiermon
javiermon / latency.txt
Created December 15, 2022 01:22 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@javiermon
javiermon / log.c
Last active September 28, 2022 23:34
va_args logging
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
typedef signed int Int;
typedef unsigned int Uint;
@javiermon
javiermon / hexdump.c
Last active May 31, 2022 23:01
hexdump.c
#include <stdio.h>
void hexDump(char *desc, void *addr, int len)
{
int i;
unsigned char buff[17];
unsigned char *pc = addr;
// Output description if given.
if (desc != NULL)
@javiermon
javiermon / nprocnetdev.c
Last active January 7, 2022 18:13
nprocnetdev.c: print proc/net/dev via netlink sockets
/*
gcc -g -o nprocnetdev nprocnetdev.c
Originally based on:
http://www.iijlab.net/~jean/iflist.c
Reference:
http://iijean.blogspot.com/2010/03/howto-get-list-of-network-interfaces-in.html
*/
@javiermon
javiermon / LICENSE
Created August 9, 2021 23:30 — forked from domnikl/LICENSE
C function to dump memory
Copyright 2018 Dominik Liebler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR O
import sys
# example:
# python int2ip.py -1062731768
# 192.168.0.8
#
# stolen from: https://pastebin.com/icqSZhYt
def int_to_ip(signed_int):
""" convert a 32-bit signed integer to an IP address"""
@javiermon
javiermon / gist:515672612abf3ffae27f0ae306c76e26
Created December 12, 2019 01:19 — forked from trodrigues/gist:1023167
Checkout only certain branches with git-svn
If you want to clone an svn repository with git-svn but don't want it to push all the existing branches, here's what you should do.
* Clone with git-svn using the -T parameter to define your trunk path inside the svnrepo, at the same time instructing it to clone only the trunk:
git svn clone -T trunk http://example.com/PROJECT
* If instead of cloning trunk you just want to clone a certain branch, do the same thing but change the path given to -T:
git svn clone -T branches/somefeature http://example.com/PROJECT
#!/usr/bin/python
# https://www.saltycrane.com/blog/2007/11/remove-c-comments-python/
import re
import sys
def remove_comments(text):
""" remove c-style comments.
text: blob of text with comments (can include newlines)
returns: text with comments removed