Skip to content

Instantly share code, notes, and snippets.

View agarie's full-sized avatar

Carlos Agarie agarie

View GitHub Profile
@agarie
agarie / poly.rb
Created July 14, 2014 20:12
DSL for symbolic integration of polynomials
def polynomial(&block)
varX = Variable::Local.new('x')
x = Polynomial.valueOf(Real::ONE,varX)
yield x
end
# Creating a polynomial fx = 1(x^5) + 6(x^2).
fx = polynomial do |x|
x.pow(5).plus(x.pow(2).times(Real.valueOf(6)))
end
@agarie
agarie / icc.js
Created November 6, 2014 18:04
Item Characteristic Curve plotting with d3js.
var N = 100,
a = 2.0,
b = 0.0,
c = 0.2;
var defaultScale = { mu: 0, sigma: 1 },
enemScale = { mu: 500, sigma: 100 };
// @return: The probability of hit at `theta`, or P(right | theta, a, b, c).
var prob = function (a, b, c, theta) {
return c + (1 - c) / (1 + Math.exp(- a * (theta - b)));
@agarie
agarie / ngrams.rb
Created April 14, 2015 18:19
Generate {uni,bi,tri}grams from a token list.
class Counter
def initialize
@counts = Hash.new 0
end
def <<(key)
@counts[key] += 1
end
end
@agarie
agarie / create_has_library.rb
Created May 23, 2015 04:08
A function for inquiring if a library is available. Automatically requires the library if it is available.
# Create a method `has_<library>?` on Module that requires the library and
# return a boolean indicating if the library is available.
#
# @param library [String] The library name.
# @return [Boolean] Whether the library is available or not.
def create_has_library(library) #:nodoc:
define_singleton_method("has_#{library}?") do
cv = "@@#{library}"
unless class_variable_defined? cv
begin
@agarie
agarie / rng.lua
Created June 12, 2015 00:38
RNGs for some distributions written in Lua, mostly as a first exercise in the language.
-- Some RNGs for getting to play with Lua.
--
-- Carlos Agarie <carlos@onox.com.br>
--
-- Public domain.
-- N(mean; std^2).
function gauss(mean, std)
if std <= 0.0 then error("standard deviation must be positive!") end
@agarie
agarie / ajax-other-domains.js
Created April 28, 2012 05:32
Sending AJAX requests to other domains
/*
Used when you need a JSON feed from your other domain. Need a
Content-type of application/json, so be sure to use the correct
HTTP header in your app (at the other domain).
*/
// blabla just don't forget jQuery
$.ajax({
url: "another domain generating a JSON",
@agarie
agarie / natures
Created May 3, 2012 13:29
All the natures from the Pokémon series, with the corresponding increasing/decreasing stats names.
{
hardy: {
increase: "none",
decrease: "none"
},
docile: {
increase: "none",
decrease: "none"
},
serious: {
@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>
@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 / 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