Skip to content

Instantly share code, notes, and snippets.

@diabloneo
diabloneo / timespec_diff.c
Created March 18, 2014 13:22
Calculate diff of two struct timespec
#include <time.h>
void timespec_diff(struct timespec *start, struct timespec *stop,
struct timespec *result)
{
if ((stop->tv_nsec - start->tv_nsec) < 0) {
result->tv_sec = stop->tv_sec - start->tv_sec - 1;
result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000;
} else {
result->tv_sec = stop->tv_sec - start->tv_sec;
@diabloneo
diabloneo / rds_authenticator.py
Created September 2, 2013 11:35
Calculate RADIUS packet authenticator. Input packet's hex string, output authenticator in hex form.
#!/usr/bin/env python
import hashlib
import base64
import binascii
def main():
pktstr = raw_input()
m = hashlib.md5()
m.update(base64.b16decode(pktstr.replace(' ', '').upper()))
@diabloneo
diabloneo / tmux_start.sh
Created November 27, 2012 13:37
Starting tmux with specific windows
#!/bin/bash
ROOTDIR=~/ruijie
SESSION=main
NONAME="bash"
window_list="tftp $NONAME ipython $NONAME"
tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
echo "Session $SESSION already exists. Attacing."