Skip to content

Instantly share code, notes, and snippets.

View PhDP's full-sized avatar
🏠
Working from home

Philippe Desjardins-Proulx PhDP

🏠
Working from home
View GitHub Profile
@PhDP
PhDP / measure.cc
Last active December 20, 2015 07:29
The measure as defined in the Porter algorithm.
/**
* Computes the measure of an English word as defined for the Porter algorithm.
* The definition of the measure can be found here:
* http://snowball.tartarus.org/algorithms/porter/stemmer.html
*
* ...but it's overtly complicated. Here's my definition:
*
* The *measure* of a word is the number of vowels followed by a consonant.
*
* Examples:
@PhDP
PhDP / stemmers.cc
Last active December 20, 2015 07:59
Rough draft of a stemmer and english stemmer classes
/////////////////////////
// stemmer.hh //
/////////////////////////
#pragma once
#include <iostream>
#include <string>
/**
@PhDP
PhDP / main.cc
Created August 2, 2013 17:37
"Monte Carlo" example (Introductory C++)
/*
phdp@dell-xps:~$ vim main.cc
phdp@dell-xps:~$ clang++ -std=c++11 main.cc -o main
phdp@dell-xps:~$ time ./main
The seed is 1375464851
3.14157
real 0m27.375s
user 0m27.308s
sys 0m0.004s
@PhDP
PhDP / sum.c
Created August 24, 2013 03:15
If variance is great, summing the values of an array can be problematic. The problem can often be solved by sorting the array before summing.
double sum_d(const double *x, size_t length) {
double sum = 0.0;
for (size_t i = 0; i < length; ++i) {
sum += x[i];
}
return sum;
}
double srtsum_d(const double *x, size_t length) {
// Copy the array & sort it with quicksort.
@PhDP
PhDP / Well.cs
Created September 22, 2013 18:11
The Well1024 random number generator in C#
namespace Utils
{
class Well
{
private uint seed;
private uint state_n;
private uint[] state;
private uint mat3pos(int t, uint v)
{
@PhDP
PhDP / preferences.json
Created October 19, 2013 18:36
Basic Sublime Text 2 options
{
"color_scheme": "Packages/Color Scheme - Default/Solarized (Light).tmTheme",
"font_face": "Ubuntu Mono",
"font_size": 16,
"tab_size": 2,
"translate_tabs_to_spaces": true
}
@PhDP
PhDP / paip2.cl
Last active December 26, 2015 13:29
String-based functions for Norvig's PAIP (chapter 2).
;;;;;;;;;;;;;
; Chapter 2 ;
;;;;;;;;;;;;;
(defun en-sentence ()
"An English sentence."
(append (en-noun-phrase) (en-verb-phrase)))
(defun en-noun-phrase ()
"An English noun-phrase."
@PhDP
PhDP / scriptoria-scheme.json
Last active December 26, 2015 17:09 — forked from tpoisot/scriptoria-scheme.json
First draft of Scriptoria's JSON schema (has bugs I think).
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Scriptoria object",
"description": "Meta-data about a publication registered in scriptoria",
"type": "object",
"properties": {
"source": {
"description": "URL of the original repository",
"type": "string"
},
@PhDP
PhDP / flags.json
Last active December 29, 2015 20:49
Flag data-set in JSON format.
{
"Title": "Flags",
"URL": "http://orange.biolab.si/datasets.psp",
"Variables": ["Landmass", "Zone", "Area", "Population", "Language", "Religion", "Bars", "Stripes", "Colors", "Red", "Green", "Blue", "Gold", "White", "Black", "Orange", "MainHue", "Circles", "Crosses", "Saltires", "Quarters", "Sunstars", "Crescent", "Triangle", "Icon", "Animate", "Text", "TopLeft", "BotRight"],
"Records name": ["Afghanistan", "Albania", "Algeria", "American-Samoa", "Andorra", "Angola", "Anguilla", "Antigua-Barbuda", "Argentina", "Argentine", "Australia", "Austria", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Botswana", "Brazil", "British-Virgin-Isles", "Brunei", "Bulgaria", "Burkina", "Burma", "Burundi", "Cameroon", "Canada", "Cape-Verde-Islands", "Cayman-Islands", "Central-African-Republic", "Chad", "Chile", "China", "Colombia", "Comorro-Islands", "Congo", "Cook-Islands", "Costa-Rica", "Cuba", "Cyprus", "Czechoslovakia", "Denmark", "Djibouti", "Dominic
{
"Title": "Flags",
"URL": "http://orange.biolab.si/datasets.psp",
"Variables": ["Landmass", "Zone", "Area", "Population", "Language", "Religion"],
"Records name": ["Afghanistan", "Albania", "Algeria", "American-Samoa", "Andorra"],
"Data": [
[5,1, 648,16,10,2],
[3,1, 29, 3, 6,6],
[4,1,2388,20, 8,2],
[6,3, 0, 0, 1,1],