Skip to content

Instantly share code, notes, and snippets.

@carld
carld / .guile
Created October 6, 2015 05:33
guile readline
(use-modules (ice-9 readline))
(activate-readline)
@carld
carld / guile-crypt.scm
Created February 27, 2016 02:43
guile foreign function crypt example
(use-modules (system foreign))
(define crypt
(let ((f (pointer->procedure '* (dynamic-func "crypt" (dynamic-link))
(list '* '*))))
(lambda (key salt)
(let ((r (f (string->pointer key) (string->pointer salt))))
(pointer->string r)))))
(simple-format #t "Test: ~s" (crypt "key" "salt"))
@carld
carld / gist:442bc8edb9b991dc4c25
Created March 10, 2016 22:42
gdb ruby backtrace
gdb
(gdb) file /opt/ruby-2.2.3/bin/ruby
(gdb) attach [pid]
# output of the C backtrace goes to the gdb console
(gdb) eval "backtrace"
# output of the Ruby application backtrace below goes to ruby stdout (rails logger?)
(gdb) call rb_backtrace()
(gdb) continue
@carld
carld / gist:68ead3966e9c233f7e47
Created March 10, 2016 22:44
ssh port forwarding
ssh -nNT -L [local port]:[remote IP addr]:[remote port] user@machine-with-access-to-remote
@carld
carld / gist:87f2453ed622f92f220451b7e8ae6a26
Created April 29, 2016 01:28
go through all directories, test for .git/ and diff stat two branches
for dir in `find . -type d -depth 1`; do
cd $dir;
if [ -d .git ]; then
if git branch -ra | grep -q "$B2\$"; then
echo $dir;
git diff --shortstat $B1 $B2;
fi
fi
cd ..;
done
require 'rails_erd/diagram/graphviz'
RailsERD::Diagram::Graphviz.create
@carld
carld / prepare-commit-msg
Created September 7, 2016 00:23
pleasant lawyer git hook prepare-commit-msg, .git/hooks/prepare-commit-msg
#!/usr/bin/env ruby
require 'pleasant_lawyer'
git_branch_name = `git symbolic-ref -q HEAD`
branch_name = File.basename(git_branch_name).gsub(/_/," ")
file = File.open(ARGV[0], 'r')
contents = file.read
file.close
File.open(ARGV[0], 'w') do |file|
file.write("B##{PleasantLawyer.convert(branch_name)} ") if branch_name.split(/ /).length == 2
file.write(contents)
@carld
carld / str.s
Created September 10, 2016 07:34
string equals in x86_64 nasm assembly
section .text
global start
start:
mov rsi, s1 ; esi = &s1
mov rdi, s2 ; edi = &s2
xor rdx, rdx ; edx = 0
loop:
mov al, [rsi + rdx]
mov bl, [rdi + rdx]
inc rdx
@carld
carld / git-side-by-side
Created September 21, 2016 23:03
git diff side by side in colour
git difftool -y -x "colordiff -y -W $COLUMNS" origin/prod origin/master | less -R