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 / 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 / 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 / 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 / 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 / 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 / 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 / lux
Last active December 20, 2015 06:29
Ruby script to set the brightness on my Dell XPS (the normal way fails after Ubuntu 13.04).
#!/usr/bin/env ruby
if ARGV.length != 1 then
puts 'Provide a single argument between 0.1 (nearly black) and 1.0 (max brigthness).'
exit(42)
end
b = ARGV[0].to_f
b = (if b < 0.1 then 0.1 elsif b > 1.0 then 1.0 else b end).to_s
@PhDP
PhDP / scriptoria-mockup.html
Last active December 19, 2015 03:49
A first (failed) design for Scriptoria based on a Bootstrap example. I like the Orange/Red theme (revolution!!!!), and I like the idea of having each article in a small touch-friendly orange box, but it's very hard to read... UPDATE: I now use a less obnoxious color theme.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Scriptoria -- a database of scientific documents written with distributed revision control systems.</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
@PhDP
PhDP / yesod-ubuntu13.04.md
Last active December 19, 2015 02:59
Making Yesod work on Ubuntu 13.04

For a project named XXX with a postgreSQL database:

  1. $ sudo apt-get install libedit-dev libbsd-dev libgmp3-dev zlib1g-dev freeglut3-dev postgresql pgadmin3 libghc-persistent-postgresql-dev cabal-install
  2. Install all packages for 'yesod'.
  3. $ cabal update
  4. $ cd XXX && cabal install && yesod devel
@PhDP
PhDP / fizzbuzz.hs
Created June 28, 2013 17:50
fizzbuzz
fizzbuzz a b x = [fb i | i <- [1..x]]
where
ab = a * b
fb n
| mod n ab == 0 = "FizzBuzz"
| mod n a == 0 = "Fizz"
| mod n b == 0 = "Buzz"
| otherwise = show n
main = mapM_ print $ fizzbuzz 5 7 1000