Skip to content

Instantly share code, notes, and snippets.

View macournoyer's full-sized avatar

Marc-André Cournoyer macournoyer

View GitHub Profile
@macournoyer
macournoyer / tm_reveal_in_github.rb
Created January 14, 2011 15:31
Reveal in GitHub TextMate command
#!/usr/bin/env ruby
# Reveal in GitHub TextMate command
require 'pathname'
path = Pathname.new(ENV["TM_FILEPATH"]).relative_path_from(Pathname.new(ENV["TM_PROJECT_DIRECTORY"]))
repo_path = `/usr/local/bin/git remote show origin`[/Fetch URL: git@(.*)\.git$/, 1].tr(":", "/")
branch = `/usr/local/bin/git symbolic-ref HEAD`[/refs\/heads\/(.*)$/, 1]
exec "open 'http://#{repo_path}/blob/#{branch}/#{path}'"
@macournoyer
macournoyer / app.ru
Created August 19, 2011 17:02
The invisible block web framework. In honor of _why.
# rackup app.ru
require "./invisible"
app = Invisible.new do
get "/" do
render do
h1 "Why?"
p "Because."
end
@macournoyer
macournoyer / mio.rb
Created November 4, 2011 04:01
mio
#!/usr/bin/env ruby
# mio -- minimalist language inspired by Io for your own careful
# and private delectation w/ friends of the the family,
# if you want to.
# usage:
# mio # starts the REPL
# mio mio_on_rails.mio
# (c) macournoyer
module Mio
class Error < RuntimeError
@macournoyer
macournoyer / gist:1812942
Created February 13, 2012 02:53
My bash prompt
function parse_git_branch {
ref=`git symbolic-ref HEAD 2> /dev/null` || return
branch="${ref#refs/heads/}"
if [ $branch != "master" ]
then
echo "($branch)"
fi
}
function parse_rvm_prompt {
@macournoyer
macournoyer / .gitconfig
Last active September 30, 2015 23:18
Git shortcuts
[alias]
st = status
s = status
co = checkout
c = commit -v
ci = commit -a -v
b = branch
d = diff
p = pull
a = add -A .
class ModifyResponseHeaders
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers["cache"] = "..."
[status, headers, body]
end
@macournoyer
macournoyer / abc.rb
Created November 5, 2012 17:16
First programming lesson w/ my 4yo daughter
alphabet = 'A'..'Z'
`say "#{alphabet.to_a.join(', ')}"`
@macournoyer
macournoyer / Dockerfile
Last active December 14, 2019 16:31
Playing w/ Dockerfile on OS X
FROM base
MAINTAINER Marc-Andre Cournoyer "macournoyer@gmail.com"
RUN apt-get -y update
RUN apt-get install -y -q curl
RUN curl -L https://get.rvm.io | bash -s stable --ruby
RUN /bin/bash -l -c rvm requirements
include Math;R1=1.0; R2=2.0;K2=5.0
SS=40;K1=SS*K2*3/(8*(R1+R2));def rf(a, b)
cosA=cos(a);sinA=sin(a);cosB=cos(b);sinB=sin(b)
o=Array.new(SS).fill{Array.new(SS).fill(' ')};b=Array.
new(SS).fill{ Array.new(SS).fill(0)}; t=0.0;while t<2*PI
cost=cos(t);sint=sin(t);p=0.0;while p<2*PI;cosp=cos(p);sinp=
sin(p);cx=R2+R1*cost;cy=R1* sint;x=cx*(cosB*cosp+sinA*
sinB*sinp)-cy*cosA*sinB; y=cx*(sinB*cosp-sinA*##
cosB*sinp)+cy*cosA*cosB ;z=K2+cosA*cx*sinp+cy*
sinA;ooz=1/z;xp=(SS/2+K1* ooz*x).to_i ;yp= (SS/2-