Skip to content

Instantly share code, notes, and snippets.

Marc-André Cournoyer macournoyer

View GitHub Profile
@macournoyer
macournoyer / Output
Last active Mar 14, 2019
A Neural Network framework in 25 LOC
View Output
$ python xor.py
Training:
Epoch 0 MSE: 1.765
Epoch 100 MSE: 0.015
Epoch 200 MSE: 0.005
* Target MSE reached *
Evaluating:
1 XOR 0 = 1 ( 0.904) Error: 0.096
0 XOR 1 = 1 ( 0.908) Error: 0.092
1 XOR 1 = 0 (-0.008) Error: 0.008
@macournoyer
macournoyer / game.litcoffee
Last active Apr 14, 2017
JavaScript Game Basics in (Literate) CoffeeScript http://macournoyer.com/game/
View game.litcoffee

The game we're building is a simple side-scrolling racing game. The player's car is static on the screen, only the background is moving. The enemies are planes whom the player must dodge using the up and down arrow keys. If the player hits a plane, he dies. One point is given each time a plane goes off screen without touching the player.

Sprites

Our game is composed of sprites. Each sprite has a position (x, y), velocity (speed) and one image, or more if animated.

Images are loaded from the DOM using their CSS selector (imagesSelector). We use ID selectors (#name) for single images and class selectors (.name) for animated sprites composed of several images.

See the images used in the game.

@macournoyer
macournoyer / RubyEval.py
Created Sep 13, 2013
Sublime Text 2 RubyEval hack
View RubyEval.py
import subprocess
import sublime, sublime_plugin
class EvalAsRuby:
def ruby(self):
try:
return self.view.settings().get("ruby_eval").get("ruby")
except AttributeError:
return "ruby"
View donut.rb
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-
@macournoyer
macournoyer / Dockerfile
Last active Jan 27, 2016
Playing w/ Dockerfile on OS X
View Dockerfile
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
@macournoyer
macournoyer / abc.rb
Created Nov 5, 2012
First programming lesson w/ my 4yo daughter
View abc.rb
alphabet = 'A'..'Z'
`say "#{alphabet.to_a.join(', ')}"`
View gist:3298395
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 / .gitconfig
Last active Sep 30, 2015
Git shortcuts
View .gitconfig
[alias]
st = status
s = status
co = checkout
c = commit -v
ci = commit -a -v
b = branch
d = diff
p = pull
a = add -A .
View gist:1812942
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 {
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.