Skip to content

Instantly share code, notes, and snippets.

@oliverdaff
oliverdaff / Diesel_Rust_ORM_Learning_Pathway.md
Created March 19, 2024 02:37
Diesel Rust ORM Leaning Pathway

Diesel learning pathway

  1. Diesel CLI : Familiarise with Diesel's command-line tools for managing projects and migrations.
  2. Migrations: Understand managing database schema changes over time with Diesel's ]LI.
  3. Schema Management: Learn how Diesel uses schema.rs and the table! macro to reflect database structures.
  4. Type Safety and Conversion : Grasp how Rust types correspond to SQL types and handling custom types.
  5. Query Builder: Learn to construct SQL queries using Rust, utilising methods like filter, order, and limit
  6. CRUD Operations: Understand how to perform create, read, update, and delete operations using Diesel.
  7. Connection Handling: Learn about managing database connections, executing queries, and handling transactions.
  8. Associations and Joins: (TODO) Learn about expressing r
@oliverdaff
oliverdaff / tracing-instrument-macro.md
Created January 4, 2024 01:13
Tutorial on Using the tracing::instrument Macro in Rust

Tutorial on Using the tracing::instrument Macro in Rust

Introduction

This document provides a comprehensive guide on using the tracing::instrument macro in Rust. It covers the basics of the tracing crate, the purpose and functioning of the instrument macro, and best practices for its effective use in software development.

What is the tracing::instrument Macro?

  • Overview: The tracing crate is a collection of Rust libraries for application-level tracing and asynchronous diagnostics. It provides a framework for collecting structured, event-based diagnostic information. The instrument macro, specifically, is a part of this crate. It automatically attaches context-specific information to logs, such as function arguments and return values, making it easier to track the flow and performance of the code.

  • Purpose: The primary purpose of the tracing::instrument macro is to aid in diagnostics and performance analysis. By annotating functions with this macro, developers can automatic

@oliverdaff
oliverdaff / nmap_fast.sh
Last active September 14, 2020 00:59
Use nmap to find open ports fast and then run a detailed scans on the returned ports
#!/bin/bash
# Use nmap to find open ports fast and then run a detailed scans on the returned ports
if [ -z "$1" ]
then
echo "__nmap_fast__"
echo "Usage: ./nmap_fast TARGET_HOSTNAME"
fi
TARGET_HOSTNAME=$1
@oliverdaff
oliverdaff / gist:c8305a3745e6a238bcde10d303f0e3f8
Created November 20, 2019 22:53
encrypt a dir with tar and open ssl
## Encrypt
tar cz folder | openssl aes-256-cbc -salt -pbkdf2 -e > out.tar.gz.enc
## Decrypt
openssl aes-256-cbc -d -salt -pbkdf2 -in out.tar.gz.enc | tar xz
@oliverdaff
oliverdaff / sage_maker_conda_env.sh
Created March 14, 2019 09:41
Script to set up AWS Sagemaker with a anaconda env and make kernel available in ipython.
#!/bin/bash
set -e
sudo -u ec2-user -i <<'EOF'
conda create --prefix ~/your_project -y -c conda-forge python=3.7 ipykernel
source activate /home/ec2-user/your_project
conda install -y your_libs
python -m ipykernel install --user
@oliverdaff
oliverdaff / binarysearch.sh
Created July 23, 2013 23:40
Bash Script Binary Search
binary_search(){
TARGET=$1
TO_SEARCH=(${@:2})
LENGTH=${#TO_SEARCH[@]}
START=0
END=$((LENGTH - 1))
while [[ $START -le $END ]]; do
MIDDLE=$((START + ((END - START)/2)))
ITEM_AT_MIDDLE=${TO_SEARCH[MIDDLE]}
#!/bin/bash
ME=`whoami`
PROCESS=$1
echo $PROCESS
echo $ME
IPCS_S=`ipcs -s $PROCESS | egrep "0x[0-9a-f]+0-9]+" | grep $ME | cut -f2 -d" "`
IPCS_M=`ipcs -m $PROCESS | egrep "0x[0-9a-f]+[0-9]+" | grep $ME | cut -f2 -d" "`
@oliverdaff
oliverdaff / fact_curl_request.sh
Created June 7, 2012 00:23
Get facts from puppet master
#expose yam facts under /var/lib/puppet/yaml/facts/ in /etc/puppet/fileserver.conf and access via http
curl -k -H "Accept: yaml" https://puppetmaster:8140/production/facts/hostname
@oliverdaff
oliverdaff / packagefacts.rb
Created June 7, 2012 00:16
Facter to set facts of versions installed
require 'puppet'
require 'puppet/application'
require 'facter'
typeobj = Puppet::Type.type("package")
properties = typeobj.properties.collect { |s| s.name }
format = proc {|trans|
trans.dup.collect do |param, value|
if value.nil? or value.to_s.empty?
trans.delete(param)
@oliverdaff
oliverdaff / jira-precommit.sh
Created April 24, 2012 00:02
svn JIRA Precommit hook
#!/bin/sh -x
## REST API JIRA KEY check
#List of projects that do not require strict JIRA KEY commits
#list in space and case-insensitive
NON_STRICT="sports"
# Authentication credentials
username=root