Skip to content

Instantly share code, notes, and snippets.

View patshaughnessy's full-sized avatar

Pat Shaughnessy patshaughnessy

View GitHub Profile
@patshaughnessy
patshaughnessy / gist:70519495343412504686
Last active April 28, 2024 01:19
How to Debug Postgres using LLDB on a Mac
This note explains how to build Postgres from source and setup to debug it using LLDB on a Mac. I used this technique to research this article:
http://patshaughnessy.net/2014/10/13/following-a-select-statement-through-postgres-internals
1. Shut down existing postgres if necessary - you don’t want to mess up your existing DB or work :)
$ ps aux | grep postgres
pat 456 0.0 0.0 2503812 828 ?? Ss Sun10AM 0:11.59 postgres: stats collector process
pat 455 0.0 0.0 2649692 2536 ?? Ss Sun10AM 0:05.00 postgres: autovacuum launcher process
pat 454 0.0 0.0 2640476 304 ?? Ss Sun10AM 0:00.74 postgres: wal writer process
pat 453 0.0 0.0 2640476 336 ?? Ss Sun10AM 0:00.76 postgres: writer process
// Code from: http://patshaughnessy.net/2020/1/20/downloading-100000-files-using-async-rust
//
// Cargo.toml:
// [dependencies]
// tokio = { version = "0.2", features = ["full"] }
// reqwest = { version = "0.10", features = ["json"] }
// futures = "0.3"
use std::io::prelude::*;
use std::fs::File;
@patshaughnessy
patshaughnessy / application.css.less
Created November 23, 2011 20:38
application.css.less example overriding Twitter Bootstrap variable (using less-rails-bootstrap)
*
* application.css.less
*= require_self
*/
@import "twitter/bootstrap/reset.less";
@import "twitter/bootstrap/variables.less";
// Override link color for my app:
@patshaughnessy
patshaughnessy / gist:7104128
Last active April 13, 2023 20:20
Resources for learning about MRI Ruby's internal C source code
Recently someone asked me for online resources about MRI's internal C source
code. Here are a few - if there are more to add please leave a comment! - pat
1. Ruby Hacking Guide - The definitive resource for people who want to learn
the C programming details of how Ruby works internally. Intended for C hackers.
It was just recently translated into English from the original Japanese.
http://ruby-hacking-guide.github.io
2. Various presentations by Koichi Sasada - he often does public presentations
on Ruby internals and they're always fascinating and full of technical details.
@patshaughnessy
patshaughnessy / find_string_example.rs
Last active November 22, 2020 23:39
Rust Vec<String> find example
fn main() {
let needle = "list".to_string();
let haystack = ["some".to_string(), "long".to_string(), "list".to_string(), "of".to_string(), "strings".to_string()].to_vec();
if let Some(str) = haystack.iter().find(|&s| *s == needle) {
println!("{}", needle);
} else {
println!("Nothing there...");
}
}
@patshaughnessy
patshaughnessy / main.rs
Created June 9, 2018 14:42
Execute a simple SQL report using Rust and Diesel
#[macro_use]
extern crate diesel;
use diesel::prelude::*;
table! {
users (id) {
id -> Int4,
first_name -> Nullable<Varchar>,
last_name -> Nullable<Varchar>,
@patshaughnessy
patshaughnessy / ruby-book-club-questions.md
Last active August 18, 2017 19:38
Ruby Book Club Questions - Episodes 7 and 8

Hi guys, So in episode 7 you were asking about where and how the puts method connects to the computer’s display and writes the output. And in episode 8 you were asking about the times method, how that worked and why it wasn’t implemented with YARV instructions. In both cases, I didn’t go into detail about this in the book because it would have distracted you from the topic at hand, which is how YARV executes your code. (Or in this case, my example Ruby code from the book.)

Both the puts and times methods were written by the Ruby code team, and not by you or me. Both of them are implemented in C code. So when you’re writing a Ruby program, some of the methods you write yourself, but you get many other methods for free because they are part of the Ruby language. Many of the these built in methods are part of the standard library, which means they are Ruby code written by the Ruby core team, while other built in methods are written directly in C code by the Ruby team.

As you know, the puts method tak

@patshaughnessy
patshaughnessy / application.css.scss
Created November 23, 2011 20:39
application.css.scss example overriding Twitter Bootstrap variables (using bootstrap-sass)
/*
* application.css.scss
*= require_self
*/
@import "bootstrap/reset.css.scss";
@import "bootstrap/variables.css.scss";
// Override link color for my app:
# Prepare a new stack frame (save the old base pointer, and set
the new base pointer to the current stack pointer)
pushq %rbp
movq %rsp, %rbp
# Get the address of your string (lea = load effective address)
# and put it into the rdi register as a parameter to printf.
leaq L_.str(%rip), %rdi
# Not sure why this is needed - I believe it sets eax to zero.
@patshaughnessy
patshaughnessy / gist:8239185
Last active January 2, 2016 02:48
x86_64 assembly language generated for MRI rb_obj_not (object.c line 186) with modified RTEST macro
-- Change RTEST:
//#define RTEST(v) !(((VALUE)(v) & ~Qnil) == 0)
#define RTEST(v) ((VALUE)(v) != Qnil && (VALUE)(v))
-- Recompile with -S flag:
clang -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration -Werror=division-by-zero -Werror=extra-tokens -pipe -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I. -I.ext/include/x86_64-darwin12.0 -I./include -I. -S -o object.o -c object.c
-- And here's the new assembly language - it's longer with a condition in the middle (See: je LBB7_2)