This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (C) Tejas Wanjari (twanjari@andrew.cmu.edu) | |
# GNU/GPL | |
# ------- | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#include <stdio.h> | |
#include <string.h> | |
#include <arpa/inet.h> | |
#include "config.h" | |
static struct config *cfg; | |
static unsigned char key[64], value[64]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* tcpmd5_server6.c: TCP_MD5SIG | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <sys/types.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func stackDump(err *error, f interface{}) { | |
fname := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name() | |
_, file, line, _ := runtime.Caller(4) // this skips the first 4 that are called under log.Panic() | |
if r := recover(); r != nil { | |
fmt.Printf("%s (recover): %v\n", fname, r) | |
if err != nil { | |
*err = fmt.Errorf("%v", r) | |
} | |
} else if err != nil && *err != nil { | |
fmt.Printf("%s : %v\n", fname, *err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// qotd: Quote of the Day | |
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"strings" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func printSlice(s string, x []int) { | |
fmt.Printf("Slice %s len=%d cap=%d %v\n", s, len(x), cap(x), x) | |
} | |
func main() { | |
fmt.Println("Go Slice Example: Copy-on-Capacity-Overload\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Append(slice, data []byte) []byte { | |
l := len(slice) | |
if l + len(data) > cap(slice) { // reallocate | |
// Allocate double what's needed, for future growth. | |
newSlice := make([]byte, (l+len(data))*2) | |
// The copy function is predeclared and works for any slice type. | |
copy(newSlice, slice) | |
slice = newSlice | |
} | |
slice = slice[0:l+len(data)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint32_t __core_csum_tcp(uint16_t *addr, uint32_t count) | |
{ | |
register uint32_t sum = 0; | |
while (count > 1) { | |
sum += *addr++; | |
count -= 2; | |
} | |
/* Add left-over byte, if any, (zero padding) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fzf_fasd_ed () { | |
local ed=${EDITOR:-vim} | |
local file=$(fasd -Rlf | \ | |
fzf --height=40% --reverse --prompt="${ed}> ") | |
[[ -z ${file} ]] && return | |
# ${ed} ${file} < /dev/tty | |
BUFFER="${ed} ${file}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tabulate(dlist, width=12): | |
# good enough, could be sick | |
fmt = f"{{:^{width}}}|" * len(dlist) | |
sep = f"{{:^{width}}}+" * len(dlist) | |
print("+" + sep.format(*["-" * width] * len(dlist))) | |
print("|" + fmt.format(*[str(k).upper() for k, _ in dlist.items()])) | |
print("+" + sep.format(*["-" * width] * len(dlist))) | |
list_of_lists = [] | |
max_rows = 0 | |
for _, v in dlist.items(): |