Skip to content

Instantly share code, notes, and snippets.

View banister's full-sized avatar
🇳🇱

John Mair banister

🇳🇱
View GitHub Profile
@banister
banister / bpf.c
Created April 2, 2021 03:58 — forked from c-bata/bpf.c
Capture packets from bpf devices on macOS.
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <unistd.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <net/bpf.h>
@banister
banister / cool-buttons.markdown
Created December 29, 2021 06:05
Cool Buttons
/* Copied, Pasted and summarized from ps' source code.
You can use sysctl to get other process' argv.
*/
#include <sys/sysctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define pid_of(pproc) pproc->kp_proc.p_pid
command "hist", "Show and replay Readline history" do |*args|
require 'slop'
if args.empty?
text = add_line_numbers(Readline::HISTORY.to_a.join("\n"), 0)
stagger_output(text)
next
end
opts = Slop.parse(args) do
banner "Usage: hist [-rSTART..END]"
pry(Module):4> show-method define_method
--
From Ruby Core (C Method):
--
static VALUE
rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
{
ID id;
VALUE body;
int noex = NOEX_PUBLIC;

file

#!/usr/bin/env bash
CLIENT_ID=<REDACTED>
LOG_FILE=~/.image_uploader.log
touch $LOG_FILE
exec 1>>$LOG_FILE # redirect stdout to the log file
exec 2>&1 # ditto for stderr
#!/usr/bin/env bash
set -x
CLIENT_ID=<REDACTED>
LOG_FILE=~/.image_uploader.log
touch $LOG_FILE
# folder to watch
SCREENSHOT_FOLDER=/home/user/Pictures/screenshots
gitwalk() {
git log ${1}..HEAD --oneline | awk '{print $1}' | tac | xargs -I{} -n1 sh -c 'git log -p {}'
}
main() {
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"