This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prime factorization. | |
perl -le '$_= 1 x pop; print $+[1] and s/$1/1/g while /^(11+?)\1*$/' 60 | |
2 | |
2 | |
3 | |
5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |