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 / mcpi.c
Created July 28, 2014 17:21
randamu example
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <randamu/rng.h>
int main() {
const clock_t start = clock();
rd_rng r; // A random number generator.
rd_rng_init_time(&r); // Initialize with the current time.
const int max = 2000000000;
@PhDP
PhDP / debug.h
Last active August 29, 2015 14:04
Debug macros
// From: http://c.learncodethehardway.org/book/ex20.html
#ifndef __dbg_h__
#define __dbg_h__
#include <stdio.h>
#include <errno.h>
#include <string.h>
#ifdef NDEBUG
@PhDP
PhDP / appveyor.yml
Created August 21, 2014 04:24
appveyor.yml for windows (untested)
os: Windows Server 2012
platform: x64
branches:
only:
- master
install:
- cinst cmake
- cinst make

Keybase proof

I hereby claim:

  • I am phdp on github.
  • I am phdp (https://keybase.io/phdp) on keybase.
  • I have a public key whose fingerprint is 081D 2E96 EC38 85A1 4E50 5C8C 9FA9 BB43 2964 5021

To claim this, I am signing this object:

@PhDP
PhDP / vecadd.c
Created December 8, 2014 13:12
Simple opencl exaple. It works on UNIX but fails on Windows with NVIDIA drivers for some reason.
// From Gaster et al.'s "Heterogeneous Computing with OpenCL".
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#if defined(__APPLE__) && defined(__MACH__)
#include <OpenCL/OpenCL.h>
#else
#include <CL/cl.h>
@PhDP
PhDP / ross.cc
Created January 29, 2015 19:07
Loops / iterators in C++ (not tested)
// Compile with the -std=c++0x or -std=c++11 flag
#include <iostream>
#include <set>
#include <algorithm>
int main() {
// Create a set of numbers with the new initializer:
std::set<int> xs{ 6, 42, 47 };
Section "Device"
Identifier "nvidia"
Driver "nvidia"
Option "NoLogo" "true"
Option "DPI" "96 x 96"
# Specify Nvidia PCI device
BusID "PCI:1:0:0"
# Make sure X starts also when no outputs are connected to the Nvidia chip
Option "AllowEmptyInitialConfiguration"
EndSection
@PhDP
PhDP / harr1.hs
Last active August 29, 2015 14:16
First example of Harrison's "Handbook of Practical Logic and Automated Reasoning" in Haskell
data Expr =
Var String
| Const Int
| Add Expr Expr
| Mult Expr Expr
simplify1 :: Expr -> Expr
simplify1 e = case e of
Add (Const 0) x -> x
Add x (Const 0) -> x
@PhDP
PhDP / harr1.jl
Last active August 29, 2015 14:16
First example of Harrison's "Handbook of Practical Logic and Automated Reasoning" in Julia.
abstract Expr
type Const <: Expr; value::Int end
type Var <: Expr; name::String end
type Add <: Expr; left::Expr; right::Expr end
type Mult <: Expr; left::Expr; right::Expr end
add(x::Const, y::Const) = Const(x.value + y.value)
add(x::Const, y::Expr) = x.value == 0? y : Add(x, y)
add(x::Expr, y::Const) = add(y, x)
@PhDP
PhDP / harr1.cc
Last active August 29, 2015 14:16
First example of Harrison's "Handbook of Practical Logic and Automated Reasoning" in C++11. Even clang-format couldn't improve this...
#include <iostream>
#include <string>
#include <boost/variant.hpp>
struct Add;
struct Mult;
using Expr = boost::variant<int, std::string, boost::recursive_wrapper<Add>,
boost::recursive_wrapper<Mult>>;