Skip to content

Instantly share code, notes, and snippets.

View macournoyer's full-sized avatar

Marc-André Cournoyer macournoyer

View GitHub Profile
@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 / Output
Last active January 9, 2023 15:12
A Neural Network framework in 25 LOC
$ 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
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-
<!doctype html>
<html class="supports-no-js" lang="{{ request.locale.iso_code }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="theme-color" content="{{ settings.color_primary }}">
<link rel="canonical" href="{{ canonical_url }}">
{% if settings.favicon %}
@macournoyer
macournoyer / example.io
Created April 23, 2009 13:36
mio -- a lil tiny subset of Io all in Ruby
Xzibit = Object clone do(
dawg = method(what,
"yo dawg" print.
what print.
"clone" print.
self
).
so_you_can = method(
"so you can print" print.
@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
/// A solver for Ruzzle (https://www.maginteractive.com/games/ruzzle/)
/// Finds all the word combinations in a 4x4 grid of letters.
/// Requires a dictionnary (one word per line) in words.txt.
use std::collections::HashSet;
use std::fs::File;
use std::io::{self, BufReader};
use std::io::prelude::*;
const MIN_WORD_SIZE: usize = 5;
@macournoyer
macournoyer / game.litcoffee
Last active April 14, 2017 23:44
JavaScript Game Basics in (Literate) CoffeeScript http://macournoyer.com/game/

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 September 13, 2013 20:29
Sublime Text 2 RubyEval hack
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"
@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(', ')}"`