Skip to content

Instantly share code, notes, and snippets.

@Zabrane
Zabrane / -Recursive Queries Using Common Table Expressions.md
Created September 22, 2024 17:38 — forked from jbrown123/-Recursive Queries Using Common Table Expressions.md
Creating arbitrary-depth recursive queries in SQLITE (works for any SQL compliant system) using CTEs (common table expressions)

Recursive Queries Using Common Table Expressions

Common Table Expressions (CTEs) are a bit complex and difficult to understand at first blush. Many of the tutorials and examples on the net don't make it any easier for those just starting out. I thought I'd put together a quick gist that tries to simplify the concept and demonstrate how to do recursive queries using CTEs.

Keep in mind that CTEs have other uses besides just recursive queries but this gist is just about how they can be used to create recursive searches.

I'm using SQLite in this example but any SQL language that implements the WITH keyword should be able to do the same thing. If you've never used SQLite before, you are missing out on an amazing, open source, stand alone, SQL engine. I encourage you to check it out.

A practical example

@Zabrane
Zabrane / parse_xlsx.erl
Created July 19, 2024 16:22 — forked from mworrell/parse_xlsx.erl
Rudimentary XLSX parser in Erlang
-module(parse_xlsx).
-export([
parse_file/1,
fetch_worksheet/1
]).
parse_file(File) ->
case fetch_worksheet(File) of
{ok, #{ worksheet := notfound }} ->
@Zabrane
Zabrane / csv.c
Created July 5, 2024 23:15 — forked from kelas/csv.c
//!\file csv.c \brief fast csv parser
//!\file csv.c \brief fast csv parser
//MIT copyright (c) 2016 kelas <me@kel.as>
#include "___.h"
#include "csv.h"
Z FILE* infile;
Z FILE* outfile;
Z ID last_id = 0;
@Zabrane
Zabrane / macos-sudo-nopasswd.sh
Created June 16, 2024 11:09 — forked from juliyvchirkov/macos-sudo-nopasswd.sh
bash: sudo without a password on macOS
#!/bin/bash
#
# Enable nopasswd mode for sudo on macOS from the userspace in fast and totally non-interactive way
#
# Type the password last time to apply the new mode and forget it for any console task for ages
# Use the rollback to restore password protection
#
# Developed and tested by https://juliyvchirkov.github.io/ under the MIT license on macOS Big Sur 11.2.0
#
# Get latest version at https://gist.github.com/juliyvchirkov/3ca76582ed6b6a8366c9e7d60644960d
@Zabrane
Zabrane / csv.erl
Created June 10, 2024 19:38 — forked from andytill/csv.erl
Erlang state machine for parsing a CSV file
%% @author atill
%%
%% @doc
%% CSV parsing module. Parsed CSV will be processed and converted
%% into a list containing the separated values, lines are separated
%% by the newline atom.
-module(csv).
-import(lists, [reverse/1]).
@Zabrane
Zabrane / parse_csv.erl
Created June 10, 2024 19:25 — forked from artefactop/parse_csv.erl
Read csv file in Erlang
#!/usr/bin/env escript
-record(ecsv,{
state = field_start, %%field_start|normal|quoted|post_quoted
cols = undefined, %%how many fields per record
current_field = [],
current_record = [],
fold_state,
fold_fun %%user supplied fold function
}).
@Zabrane
Zabrane / iptables_blocklist.sh
Created June 2, 2024 19:18 — forked from cyrbil/iptables_blocklist.sh
A small script to create iptables rules to block known malware IPs
#!/bin/bash
set -o errexit
set -o errtrace
set -o functrace
set -o pipefail
set -o nounset
[ -z ${DEBUG+x} ] || set -o xtrace
Googlebot/2.1 (+http://www.google.com/bot.html) # Pattern: Googlebot\/ / URL: http://www.google.com/bot.html
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) # Pattern: Googlebot\/ / URL: http://www.google.com/bot.html
Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) # Pattern: Googlebot\/ / URL: http://www.google.com/bot.html
Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) # Pattern: Googlebot\/ / URL: http://www.google.com/bot.html
Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) # Pattern: Googlebot\/ / URL: http://www.google.com/bot.html
Mozilla
@Zabrane
Zabrane / httpd-log_config_module.conf
Created April 10, 2024 22:14 — forked from bla-ckbox/httpd-log_config_module.conf
log_config_module with exclusion and x-forwared-for
<IfModule log_config_module>
# Define monitor environment variable for logs exclusion
SetEnvIf User-Agent "^F5\ BIG-IP\ Monitor$" monitor=yes
# Define forwarded environment variable for logs management
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded=yes
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
@Zabrane
Zabrane / hitch.service
Created April 10, 2024 20:13 — forked from comotion/hitch.service
hitch systemd
[Unit]
Description=hitch
After=syslog.target network.target
[Service]
Type=forking
#Restart=on-failure
LimitNOFILE=131072
Environment="HITCH_OPTIONS=--config /etc/hitch/hitch.conf"