Skip to content

Instantly share code, notes, and snippets.

View patshaughnessy's full-sized avatar

Pat Shaughnessy patshaughnessy

View GitHub Profile
# Prime factorization.
perl -le '$_= 1 x pop; print $+[1] and s/$1/1/g while /^(11+?)\1*$/' 60
2
2
3
5
@patshaughnessy
patshaughnessy / gist:5672776
Last active December 17, 2015 21:09
Public Speaking Advice
Public speaking advice from a conversation between Ben Orenstein, Jeff Casimir and Katrina Owen.
Listen here: http://learn.thoughtbot.com/podcast/50
- Do remote talks via Skype with user groups or small conferences
- Don't apologize up front about how little you know or how unprepared you are
- Don't introduce yourself - people either know who are you or don't care
- Just start with the problem - why am I listening to this?
- Action right off the bat - like a James Bond movie hook people up front with something interesting
@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 / gist:8239149
Created January 3, 2014 14:53
x86_64 assembly language generated for MRI rb_obj_not (object.c line 186)
_rb_obj_not: ## @rb_obj_not
.cfi_startproc
Lfunc_begin7:
.loc 1 185 0 ## object.c:185:0
## BB#0:
pushq %rbp
Ltmp90:
.cfi_def_cfa_offset 16
Ltmp91:
.cfi_offset %rbp, -16
@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)
after :: String -> [String] -> [String]
after _ [] = []
after target (x:xs)
| isInfixOf target x = [x] ++ xs
| otherwise = after target xs
main = do
contents <- readFile "the-lake-isle-of-innisfree.txt"
putStr . unlines . after "glimmer" . lines $ contents
Wow Justin, I really loved this! My only criticism is that it’s too bad you
used CoffeeScript instead of Ruby :)
I especially loved the top-down approach you used in your example. I’ve started
to use this all the time myself. I actually wrote about this recently:
http://patshaughnessy.net/2014/2/10/use-an-ask-dont-tell-policy-with-ruby
For me, the biggest benefit of the top-down (“Ask, Don’t Tell” - apologies to
Dave Thomas) style is how it encourages a functional coding style. There are
just so many benefits of doing this. Since I’ve been doing this at a micro
@patshaughnessy
patshaughnessy / gist:a6b2c53a56d288f8dbf6
Last active August 29, 2015 14:01
Teaching Kids Programming Discussion
This weekend Ashley Williams (@ag_dubs), Jeff Casimir (@j3) and I had a brief
discussion on Twitter about teaching programming to kids. We thought this would
be a topic that many other people might be interested in too, so I setup this
page in case anyone else wants to join the discussion.
We're not sure where this will lead - as a next step we could setup a Google
group, Discourse site, Basecamp or some other forum for a longer discussion.
Here's the original Twitter conversation:
@patshaughnessy
patshaughnessy / gist:81b40188214259678541
Last active August 29, 2015 14:21
A quick look at when ActiveRecord instantiates Ruby objects
With regard to this twitter conversation:
https://twitter.com/PericlesTheo/status/601745115074420736
Hi Pericles,
This morning I took a quick look at how ActiveRecord converts the query result
back into Ruby objects.
Here’s where it happens:
@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