Skip to content

Instantly share code, notes, and snippets.

@pierrelux
pierrelux / Agent-Environment Interaction
Created September 9, 2013 21:29
The Agent-Environment Interaction figure from Reinforcement Learning: An Introduction by Richard S. Sutton and Andrew G. Barto reproduced in Tikz
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\tikzstyle{block} = [rectangle, draw,
text width=8em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex]
\begin{tikzpicture}[node distance = 6em, auto, thick]
\node [block] (Agent) {Agent};
#n###################################
## StarCluster Configuration File ##
####################################
[global]
# Configure the default cluster template to use when starting a cluster
# defaults to 'smallcluster' defined below. This template should be usable
# out-of-the-box provided you've configured your keypair correctly
DEFAULT_TEMPLATE=smallcluster
# enable experimental features for this release
#ENABLE_EXPERIMENTAL=True
@pierrelux
pierrelux / rpkginstaller.py
Created April 15, 2014 02:19
Plugin for starcluster: R package installer
# Copyright Pierre-Luc Bacon <pbacon@cs.mcgill.ca>
#
# This file is part of StarCluster.
#
# StarCluster is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# StarCluster is distributed in the hope that it will be useful, but WITHOUT
def bicgstab(x0, b, atv, eps, kmax):
n = b.shape[0]
errtol = eps*np.linalg.norm(b)
error = []
x = x0
rho = np.zeros(kmax+1)
if np.isclose(np.linalg.norm(x), 0.):
r = b
else:
@pierrelux
pierrelux / stream.py
Created April 17, 2015 21:00
Streaming plot in Bokeh
import time
import numpy as np
from bokeh.plotting import *
output_server("line_animate")
p = figure()
p.line([], [], color="#3333ee", name="My stream")
show(p)
@pierrelux
pierrelux / capture.py
Created May 25, 2015 03:16
DSLR image capture and download from Python
import os
import gphoto2 as gp
class Camera:
def __init__(self):
pass
def open(self):
self.context = gp.gp_context_new()
self.camera = gp.check_result(gp.gp_camera_new())
@pierrelux
pierrelux / communauto.py
Created August 18, 2015 19:48
Query the list of available cars from Communauto's Auto-mobile service
import json
import urllib
import urllib2
import xml.etree.ElementTree as ET
def query_automobiles():
url = 'https://www.reservauto.net/WCF/LSI/LSIBookingService.asmx/GetVehicleProposals?Callback=?'
values = {'CustomerID' : '""',
'Longitude' : '0',
'Latitude' : '0' }
@pierrelux
pierrelux / sample.py
Created August 28, 2015 23:43
Inverse transform sampling
class InverseTransform:
def __init__(self, probs, rng=None):
if np.sum(probs) < 1.:
raise ValueError('Must sum up to 1')
self.rng = rng
if rng is None:
self.rng = np.random.RandomState()
self.cdf = np.cumsum(probs)
@pierrelux
pierrelux / minim_ale.py
Created December 23, 2015 20:40
Bare minimum to interface to ALE and display the screen with Matplotlib
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from ale_python_interface import ale_python_interface as ALE
def display_ale(im, screen):
im.set_data(screen)
plt.draw()
@pierrelux
pierrelux / live.sh
Created February 14, 2017 22:01
Stream to Youtube Live using ffmpeg and save a local copy
ffmpeg -f video4linux2 -thread_queue_size 512 -input_format mjpeg -video_size hd720 -i /dev/video0 \
-f alsa -thread_queue_size 512 -i hw:1,0,0 \
-acodec mp3 -async 1 -vcodec libx264 -preset veryfast output.mp4 \
-acodec mp3 -ar 44100 -vcodec libx264 -preset ultrafast -maxrate 1984k -bufsize 3968k -g 60 -f flv rtmp://x.rtmp.youtube.com/live2/yourid