Skip to content

Instantly share code, notes, and snippets.

@javiermon
javiermon / cloexec.py
Created April 14, 2015 16:40
set CLOEXEC flag on socket
import fcntl
def set_close_exec(fd):
"""
Helper to add CLOEXEC to provided file descriptor.
:param fd: int
"""
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
@javiermon
javiermon / instructions.txt
Last active November 15, 2016 00:38
sdcard4jolla
[nemo@Jolla ~]$ devel-su
Password:
[root@Jolla nemo]# cd /etc/systemd/system
[root@Jolla system]# nano mount-sd4android.service
[root@Jolla system]#
[root@Jolla system]# nano /usr/local/sbin/mount-sd4android.sh
[root@Jolla system]# chmod ug+x /usr/local/sbin/mount-sd4android.sh
[root@Jolla system]# systemctl enable mount-sd4android.service
ln -s '/etc/systemd/system/mount-sd4android.service' '/etc/systemd/system/graphical.target.wants/mount-sd4android.service'
ln -s '/etc/systemd/system/mount-sd4android.service' '/etc/systemd/system/display.service.wants/mount-sd4android.service'
@javiermon
javiermon / keybase.md
Created January 19, 2015 13:57
keybase.md

Keybase proof

I hereby claim:

  • I am javiermon on github.
  • I am javiermon (https://keybase.io/javiermon) on keybase.
  • I have a public key whose fingerprint is 53F0 38AF 631E 38B7 0992 E5D4 BC67 49E8 F676 0D3E

To claim this, I am signing this object:

@javiermon
javiermon / submac.c
Created November 6, 2014 15:32
Substract Mac addresses
#include <stdint.h>
#include <stdio.h>
#define ETH_ALEN 6
int main(void)
{
uint8_t mac1[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0xFF};
uint8_t mac2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
uint64_t a = (uint64_t)mac1[5] +
@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 / route_dump.c
Last active August 29, 2015 14:08 — forked from cl4u2/route_dump.c
/*
iflist.c : retrieve network interface information thru netlink sockets
(c) Jean Lorchat @ Internet Initiative Japan - Innovation Institute
v1.0 : initial version - Feb 19th 2010
This file was obtained at the following address :
http://www.iijlab.net/~jean/iflist.c
/*
* "untar" is an extremely simple tar extractor:
* * A single C source file, so it should be easy to compile
* and run on any system with a C compiler.
* * Extremely portable standard C. The only non-ANSI function
* used is mkdir().
* * Reads basic ustar tar archives.
* * Does not require libarchive or any other special library.
*
* To compile: cc -o untar untar.c
@javiermon
javiermon / inotify_directory.c
Last active June 7, 2017 06:00
inotify_directory.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <linux/inotify.h>
#include <signal.h>
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
@javiermon
javiermon / mac2bin.py
Last active August 29, 2015 14:01
mac2bin.py
#!/usr/bin/python
# netaddr does this and more:
# >>> import netaddr
# >>> netaddr.EUI('d4:be:d9:23:d5:bf').words
import sys
if len(sys.argv) != 2:
print "usage %s mac-addr" % sys.argv[0]
sys.exit(-1)