Skip to content

Instantly share code, notes, and snippets.

View jesselawson's full-sized avatar
:shipit:

Jesse Lawson jesselawson

:shipit:
View GitHub Profile
@jesselawson
jesselawson / gitstats.sh
Created February 17, 2022 04:46
A useful shell script for emitting your contributions to whichever repo you're currently in
#!/usr/bin/env bash
git log --pretty=format:'' --numstat "$@" | awk 'NF' | awk '{insertions+=$1; deletions+=$2} END {print NR, "files changed,", insertions, "insertions(+),", deletions, "deletions(+)"}';
@jesselawson
jesselawson / auto_block_banned_ips.md
Last active February 12, 2022 15:07
Automatically Block Banned IPs with fail2ban, iptables, and ipset

In this tutorial, we'll develop a script that will get all the IP addresses blocked by fail2ban on the ssh chain and then add them to an ipset that will be automatically blocked by iptables. Talk about power traffic management!

One of the most frustrating parts about running a web hosting company is the exposure to spam and bad bot traffic. At my old hosting company, I often had to scrub through IP logs to determine what traffic was legitimate and what traffic should have been blocked outright. In fact, more web hosting companies could do this but they choose not to because more traffic = more money.

@jesselawson
jesselawson / flush_block_list.sh
Created February 12, 2022 05:21
The last "Refresh my ipset drop list" script you'll ever need
#!/usr/bin/env bash
ipset -q flush ipsum
ipset -q create ipsum hash:net
for ip in $(curl --compressed https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt 2>/dev/null | grep -v "#" | grep -v -E "\s[1-2]$" | cut -f 1); do ipset add ipsum $ip; done
# Add any IPs here that may not be in the block list yet:
ipset add ipsum 110.169.9.43
"""
Example 2
Introducing both kinds of comments, and using them to explain in detail the
elements of Example 1.
"""
# A 'comment' is code that is ignored by a language's compiler or interpreter.
# Python ignores any line that starts with the octothorpe (`#`).
# You might be more familiar with the term 'hash' or 'pound sign' for the # character.
@jesselawson
jesselawson / main.rs
Last active October 22, 2019 00:01
parse_markdown_file() function testing
use std::path::Path;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::io::Write;
fn parse_markdown_file(_filename: &str) {
print_short_banner();
println!("[ INFO ] Starting parser!");
@jesselawson
jesselawson / main.rs
Last active June 9, 2022 05:47
Fifth Checkpoint, Getting Started with Rust by Building a Tiny Markdown Compiler (https://jesselawson.org/tutorials)
// Code for the Fifth Checkpoint
// Tutorial: https://jesselawson.org/rust/get-started-with-rust-by-building-a-tiny-markdown-compiler/
//
// The purpose of this checkpoint is to ensure that you have a complete copy
// of the code in the tutorial up to the checkpoint. I want you to tinker and
// explore, but to keep up with the rest of the tutorial, make sure your
// code matches this checkpoint.
use std::path::Path;
use std::fs::File;
@jesselawson
jesselawson / main.rs
Last active October 22, 2019 00:00
Fourth Checkpoint, Getting Started with Rust by Building a Tiny Markdown Compiler (https://jesselawson.org/tutorials)
// Code for the Fourth Checkpoint
// Tutorial: https://jesselawson.org/rust/get-started-with-rust-by-building-a-tiny-markdown-compiler/
//
// The purpose of this checkpoint is to ensure that you have a complete copy
// of the code in the tutorial up to the checkpoint. I want you to tinker and
// explore, but to keep up with the rest of the tutorial, make sure your
// code matches this checkpoint.
fn parse_markdown_file(_file: &str) {
println!("[ INFO ] Trying to parse {}...", _file);
@jesselawson
jesselawson / main.rs
Last active October 22, 2019 00:01
Third Checkpoint, Getting Started with Rust by Building a Tiny Markdown Compiler (https://jesselawson.org/tutorials)
// Code for the Third Checkpoint
// Tutorial: https://jesselawson.org/rust/get-started-with-rust-by-building-a-tiny-markdown-compiler/
//
// The purpose of this checkpoint is to ensure that you have a complete copy
// of the code in the tutorial up to the checkpoint. I want you to tinker and
// explore, but to keep up with the rest of the tutorial, make sure your
// code matches this checkpoint.
fn parse_markdown_file() {
// This will be created in Chapter 4
@jesselawson
jesselawson / main.rs
Last active October 22, 2019 00:01
Second Checkpoint, Getting Started with Rust by Building a Tiny Markdown Compiler (https://jesselawson.org/tutorials)
// Code for the Second Checkpoint
// Tutorial: https://jesselawson.org/rust/get-started-with-rust-by-building-a-tiny-markdown-compiler/
//
// The purpose of this checkpoint is to ensure that you have a complete copy
// of the code in the tutorial up to the checkpoint. I want you to tinker and
// explore, but to keep up with the rest of the tutorial, make sure your
// code matches this checkpoint.
fn get_version() -> u16 {
1000
@jesselawson
jesselawson / dynamic_strings_example.c
Created April 24, 2019 15:50
An example of how you can use malloc(), realloc(), and free() to create dynamic strings.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void) {
// sizeof(char) is always 1, but we have it here
// for instructional purposes
char* full_name = malloc(sizeof(char)*strlen("Jesse Lawson")+1);
strcpy(full_name, "Jesse Lawson");