Skip to content

Instantly share code, notes, and snippets.

View jlmelville's full-sized avatar

James Melville jlmelville

View GitHub Profile
@jlmelville
jlmelville / get_seed.R
Created January 19, 2019 02:16
generating a seed for use in Rcpp
# http://rorynolan.rbind.io/2018/05/08/rcsetseed/
get_seed <- function() {
sample.int(.Machine$integer.max, 1)
}
@jlmelville
jlmelville / isomap_data.R
Last active September 12, 2022 23:56
Reading Isomap data into R
### Swiss Roll
# Install the R.matlab package:
# install.packages("R.matlab")
# downloads and reads Swiss Roll data
# returns a list:
# X.data a 3 x 20000 matrix of the column-stored X, Y, Z data
# Y.data a 2 x 20000 matrix of what I assume is the unrolled data coordinates
read_isoswiss <- function(url = "http://web.mit.edu/cocosci/isomap/swiss_roll_data.mat") {
@jlmelville
jlmelville / rkeras.md
Last active January 24, 2021 19:43
R, keras, tensorflow, windows 10, GPUs

I'm on Windows 10, and also in possession of an NVidia GTX 1080, which I lied to myself was for getting to grips with deep learning and not for playing video games. I was having trouble installing the keras package with GPU support from the instructions. The CPU version installed fine, but when I tried to install the GPU-aware version I got the dreaded "Error: Python module was not found" error. Oh, and I also repeatedly got an error about the wrong version of NumPy being found.

Somehow I managed to fix this. I think the main thing was to manually install a conda environment, rather than leaving it to the install_keras command in R. I don't have much advice on installing CUDA and cuDNN. I definitely installed CUDA 10 (and was using tensorflow 1.13 that is supposed to use that), but I may well have attempted to put previous version on my path during attempts to get this to work, or maybe the conda stuff below took c

@jlmelville
jlmelville / git-fetch.md
Last active September 28, 2023 14:54
fetching and merging forks
# Basic .gitconfig stuff
[core]
    editor = vim
[pull]
    rebase = false
# Enforce SSH
# https://stackoverflow.com/a/36500841
[url "ssh://[email protected]/"]
  insteadOf = https://github.com/
@jlmelville
jlmelville / settings.json
Last active February 27, 2021 00:35
Windows Python-based VS Code settings with lots of linting turned on
// Mercifully, comments are allowed in VS Code JSON
// "Global" User Settings:
{
"diffEditor.ignoreTrimWhitespace": false,
"editor.detectIndentation": false,
"git.autofetch": true,
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"diffEditor.renderSideBySide": false,
"workbench.colorTheme": "Dank Neon",
{"lastUpload":"2019-08-18T16:13:32.193Z","extensionVersion":"v3.4.1"}
# License: Apache 2.0
# A straightforward translation of the Python code:
turbo_colormap_data <- matrix(
c(
c(0.18995, 0.07176, 0.23217),
c(0.19483, 0.08339, 0.26149),
c(0.19956, 0.09498, 0.29024),
c(0.20415, 0.10652, 0.31844),
@jlmelville
jlmelville / settings.json
Last active October 11, 2023 00:58
VS Code settings for Linux
{
"[html]": {
"editor.insertSpaces": true,
"editor.tabSize": 2
},
"[markdown]": {
"editor.rulers": [
100
],
"editor.tabSize": 2
@jlmelville
jlmelville / linting.md
Last active March 25, 2025 15:36
Setting up Python linting with VS Code

I set up my linters for use with VS Code, so I only use the linting tools that can be integrated into the Problems tab, but these can be used from the command line. I have attempted to avoid having different tools give duplicate warnings, but this is a work in progress. The VS code settings.json is at https://gist.github.com/jlmelville/74d8fe778b0d89574e82ffe47c1e49ae.

Create a linting-requirements.txt file:

# this also installs pylint and pycodestyle
bandit
prospector[with_pyroma]
flake8
black
@jlmelville
jlmelville / vmwareplayer.sh
Created February 10, 2020 01:08
VMware player setup for Ubuntu-like
# Get copy and paste working
sudo apt-get install open-vm-tools-desktop
# Activate shared directory: name and define it (e.g. vmshare) in the VM config
# On the guest
# mkdir -p /mnt/hgfs if necessary
sudo vmhgfs-fuse .host:/vmshare /mnt/hgfs/ -o allow_other -o uid=1000 -o nonempty
# in /etc/fstab for auto mount
.host:/vmshare /mnt/hgfs/vmshare fuse.vmhgfs-fuse defaults,allow_other,uid=1000 0 0