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>
require 'deferrable_gratification'
class Promise
def initialize
@df = EM::DefaultDeferrable.new
DG.enhance! EM::DefaultDeferrable
end
def done(&block)
tap { @df.callback(&block) }
#include <iostream>
#include <type_traits>
template <typename...>
struct typelist;
template <uint32_t n, typename Head, typename...Tail>
struct nthElement;
template <uint32_t n, typename Head, typename...Tail>
@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