Skip to content

Instantly share code, notes, and snippets.

@jasonnyberg
jasonnyberg / debuginfo.c
Created March 23, 2018 20:05
Get debuginfo link filename (debian stretch) from shared lib
#include <libelf.h>
#include <elfutils/libdwelf.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include "util.h"
char *get_debug(char *filename)
{
char *b=mymalloc(256);
@jasonnyberg
jasonnyberg / snippets.sh
Last active March 15, 2017 19:16
test snippets
#mlag test traffic detection filters
for x in `seq 1 12`; do csub "{del,filter,entry,\"acl-Test-$x\"}"; done #remove
for x in `seq 1 12`; do acl allow Test-$x InPorts=$x SrcMac=0,3,1,0,0,0 SrcMacMask=255,255,255,0,0,0 ; done #add
watch -d 'showLacp; psh show filter | grep Test' #watch
bcm l2 cache show #find index of entry with "mac=01:80:c2:00:00:02"
#for instance: index -> 5 : mac=01:80:c2:00:00:02 vlan=0/0x000 modid=0 port=134217728/cpu0 prio=7 BPDU CPU ReplacePriority lookup_class =0
psh bcm l2 cache del cacheindex=5 # <- cache index from "bcm l2 cache show" # delete the entry to break lacp
psh csub "{add,l2_entry,bpdu,[1,128,194,0,0,2],7,none,[]}" # reinstall entry to restore lacp
@jasonnyberg
jasonnyberg / splitmap.erl
Created March 8, 2017 16:20
Combination of lists:split and lists:map
splitmap(F,L,N) when length(L)>N -> {L1,L2}=lists:split(N,L), [F(L1) | splitmap(F,L2,N)];
splitmap(F,L,_N) -> F(L).
@jasonnyberg
jasonnyberg / gist:6513fea76c14dab3ac0f90a4421618bf
Created March 1, 2017 16:56
Strip terminal control/text-attribute sequences in bash
noctrl() { sed 's/[\x01-\x1F\x7F]//g' | sed 's/\[[0-9]*m//g'; }
@jasonnyberg
jasonnyberg / ps3convert
Created March 4, 2012 18:15
Convert avi's that don't work on ps3 to an mp4 that does; (ps3convert ifile.xxx ofile.mp4
#usage: ps3convert infile outfile
ps3convert() { HandBrakeCLI -Z "High Profile" --subtitle-burn --subtitle 1 -i $1.* -o $1.mp4; }
@jasonnyberg
jasonnyberg / simplecli.c
Created December 15, 2011 20:15
Foundation for a really, _really_ simple cli.
int simple_cli(char *filename,int (*parser)(char *cmdline),int count)
{
FILE *ifile = NULL;
char cmdline[MAXCMDLINE];
int status = 0;
for (cmdline[0]=0;count-- && !status && (ifile = fopen(filename,"r")) != NULL;fclose(ifile),cmdline[0]=0)
while (fgets(cmdline,sizeof(cmdline)-1,ifile) && (!(status=parser(cmdline))));
return status;