Skip to content

Instantly share code, notes, and snippets.

@qpwo
qpwo / monte_carlo_tree_search.py
Last active November 13, 2024 09:29
Monte Carlo tree search (MCTS) minimal implementation in Python 3, with a tic-tac-toe example gameplay
"""
A minimal implementation of Monte Carlo tree search (MCTS) in Python 3
Luke Harold Miles, July 2019, Public Domain Dedication
See also https://en.wikipedia.org/wiki/Monte_Carlo_tree_search
https://gist.github.com/qpwo/c538c6f73727e254fdc7fab81024f6e1
"""
from abc import ABC, abstractmethod
from collections import defaultdict
import math
@aroben
aroben / git-commit-editor.vim
Last active November 10, 2024 13:23
Vim script to show git commit diff in vertical split while writing commit messages
" Put this in your .vimrc and whenever you `git commit` you'll see the diff of your commit next to your commit message.
" For the most accurate diffs, use `git config --global commit.verbose true`
" BufRead seems more appropriate here but for some reason the final `wincmd p` doesn't work if we do that.
autocmd VimEnter COMMIT_EDITMSG call OpenCommitMessageDiff()
function OpenCommitMessageDiff()
" Save the contents of the z register
let old_z = getreg("z")
let old_z_type = getregtype("z")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bshillingford
bshillingford / arxiv2kindle.ipynb
Last active March 1, 2024 12:50
arxiv2kindle: recompiles an arxiv paper for kindle-sized screens, and sends it to your wifi-enabled kindle
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@FrancescAlted
FrancescAlted / simple-key-store.py
Created January 14, 2016 12:54
A demonstration of a simple key-value store using numpy (.npz) and bcolz (ctable)
# Benchmark to compare the times for storing numpy arrays in a key-value.
# The main point is to compare numpy serialization vs a bcolz approach.
from __future__ import print_function
import sys
import os
import os.path
import subprocess
import getopt
# Context manager to generate batches in the background via a process pool
# Usage:
#
# def batch(seed):
# .... # generate minibatch
# return minibatch
#
# with BatchGenCM(batch) as bg:
# minibatch = next(bg)
# .... # do something with minibatch
@bartvm
bartvm / dl-frameworks.rst
Last active December 7, 2020 18:18
A comparison of deep learning frameworks

A comparison of Theano with other deep learning frameworks, highlighting a series of low-level design choices in no particular order.

Overview

Symbolic: Theano, CGT; Automatic: Torch, MXNet

Symbolic and automatic differentiation are often confused or used interchangeably, although their implementations are significantly different.

@d1manson
d1manson / images_in_pandas.md
Last active April 19, 2018 23:10
show images when displaying 2d arrays in iPython and Pandas

As of writing, this is only possible with my fork of pandas, but hopefully it will make its way into the main pandas stable branch.

The purpose of the fork is to let you specify a custom html formatter for individual columns in a data frame.


In this example we create a formatting function which takes a numpy array and returns a string of the form <img src='--base64-encoded-data'/>. This means that the numpy array is displayed as an image.

Below is the code we use to define our custom format function. Note that the function takes a single element from the data frame and returns and html string::

@mathisonian
mathisonian / index.md
Last active August 10, 2024 20:59
requiring npm modules in the browser console

demo gif

The final result: require() any module on npm in your browser console with browserify

This article is written to explain how the above gif works in the chrome (and other) browser consoles. A quick disclaimer: this whole thing is a huge hack, it shouldn't be used for anything seriously, and there are probably much better ways of accomplishing the same.

Update: There are much better ways of accomplishing the same, and the script has been updated to use a much simpler method pulling directly from browserify-cdn. See this thread for details: mathisonian/requirify#5

inspiration

/*
Swift Programming Language Guide
"A Swift Tour" Solutions
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html#//apple_ref/doc/uid/TP40014097-CH2-XID_1
These are the solutions to all the "experiments" in the pre-release Swift Programming Guide
(released on the same day Apple announced Swift). A couple of things worth noting:
1. Swift syntax, e.g. array declarations, has changed since I releasd these. So this code will
probably cause some errors when you paste it into a playground. Should be easy enough to fix