Skip to content

Instantly share code, notes, and snippets.

View agarie's full-sized avatar

Carlos Agarie agarie

View GitHub Profile
@agarie
agarie / naive-bayes.rb
Last active December 15, 2015 05:39
A simple implementation of the Naïve Bayes classifier for english text in Ruby. It's a prototype; more to come.
# A very simple naive bayes classifier for english text.
#
# Author: Carlos Agarie <[email protected]>
# Some assumptions:
# - The stop words, dataset and test data are hardcoded.
# - Binary classification (so each phrase has a corresponding boolean value).
# - If there's a missing feature, it's ignored.
#
# Of course this isn't a finished "product". I'm studying classifiers, so this
@agarie
agarie / gist:4753170
Created February 11, 2013 07:54
Installing ruby-opencv on OS X.
# Use Homebrew and be happy.
brew update
brew install opencv
# Give the correct pathnames. Of course, `2.4.3` is the current version at this time, change it accordingly.
gem install ruby-opencv -- --with-opencv-lib=/usr/local/Cellar/opencv/2.4.3/lib \
--with-opencv-include=/usr/local/Cellar/opencv/2.4.3/include/opencv \
--with-opencv-include=/usr/local/Cellar/opencv/2.4.3/include/opencv2
@agarie
agarie / using_rdoc.c
Last active December 10, 2015 09:48
Getting RDoc to work on C/C++ files.
/*
* This comment WON'T be processed.
*/
static VALUE undocumented_method(VALUE self) {
return Qnil;
}
/*
* This comment WILL be processed.
*/
/*
** queue-threadsafe.c
**
** A thread-safe (for 2 threads) implementation of a queue. Based on the
** implementation from the book Embedded Systems, by Jonathan W. Valvano,
** chapter 3, page 130.
*/
#include <stdlib.h>
@agarie
agarie / compiling
Created October 7, 2012 11:31
Installing ATLAS & LAPACK for NMatrix
$ rake compile
rake/gempackagetask is deprecated. Use rubygems/package_task instead
mkdir -p tmp/x86_64-darwin11.4.0/nmatrix/1.9.3
cd tmp/x86_64-darwin11.4.0/nmatrix/1.9.3
/Users/carlosagarie/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -I. ../../../../ext/nmatrix/extconf.rb
checking for clapack_dgetrf() in -llapack... no
checking for clapack.h... no
checking for cblas_dgemm() in -lcblas... yes
checking for ATL_dgemmNN() in -latlas... yes
checking for cblas.h... no
@agarie
agarie / create_input.rb
Created October 5, 2012 01:44
A basic input creation script and some random inputs generated by it.
#!/usr/bin/env ruby
#
# This script creates checkerboard inputs for CS325 Program #4.
#
# Carlos Agarie
#
prng = Random.new
# Arbitrarily decided that 80% are checkers and 20% are kings.
@agarie
agarie / quotes_generator.rb
Last active July 1, 2022 15:12
A jekyll plugin to generate a quotes index page from a quotes.json file.
#------------------------------------------------------------------------------
# QuotesGenerator
# A Jekyll plugin to generate a quotes/index.html page based on a Tumblr's
# account.
#
# You need a quotes.json file inside a SITE_ROOT/_data/ directory to use this
# plugin. It must use the same format as Tumblr's API v2.
#
# Available _config.yml settings:
# - text_size_limit: Maximum size of a used quote. Default to 1000.
@agarie
agarie / first.rb
Created September 29, 2012 05:24
Example of `yield self`
class Pokemon
def battle
yield self
end
end
mewtwo = Pokemon.new
mewtwo.battle do |m2|
puts m2
@agarie
agarie / pi.adb
Created September 10, 2012 08:02
Estimating PI through simple geometry and statistics
with Ada.Text_IO;
with Ada.Float_Text_IO;
with Ada.Numerics.Float_Random;
use Ada.Text_IO;
use Ada.Float_Text_IO;
use Ada.Numerics.Float_Random;
procedure Pi is
N: constant Integer := 500000; -- Number of iterations.
@agarie
agarie / posts-list.html
Created August 3, 2012 04:44
Creating a list of posts separated by year and month with liquid templating
<ul class="post-list unstyled">
{% for post in site.posts %}
{% capture post_year %}
{{ post.date | date: "%Y" }}
{% endcapture %}
{% unless year == post_year %}
{% assign year = post_year %}
<h1>{{ year }}</h1>