Skip to content

Instantly share code, notes, and snippets.

View basnijholt's full-sized avatar

Bas Nijholt basnijholt

View GitHub Profile
@basnijholt
basnijholt / syncthing-pi.md
Last active September 14, 2017 08:08
Set-up Raspberry Pi for Syncthing
  • Download latest Raspbian
  • Use Etcher to flash SD-card
  • touch ssh in /boot before putting the SD-card in the Raspberry Pi
  • find out the IP of Raspberry and ssh into it
  • ssh-copy-id and change password
  • Setup auto mounting of disk
  • ls -l /dev/disk/by-uuid/ and copy the UUID
  • Create the folder to mount to sudo mkdir /media/usb && sudo chown -R pi:pi /media/usb
  • Permanent mounting with sudo nano /etc/fstab and add this line at bottom: UUID=PUT_THE_UUID_HERE /media/usb ext4 defaults,noatime 0 1
  • Install syncthing with:
@basnijholt
basnijholt / fizzbizz.py
Created November 1, 2017 10:36
FizzBuzz in Python
for i in range(1, 101):
if i%15 == 0:
print('FizzBuzz')
elif i%3 == 0:
print('Fizz')
elif i%5 == 0:
print('Buzz')
else:
print(i)
@basnijholt
basnijholt / fibonacci.py
Created November 1, 2017 10:40
Fibonacci with memoizing
from functools import lru_cache
@lru_cache()
def fib(n):
if n in [0, 1]:
return 1
else:
return fib(n-1) + fib(n-2)
fib(10)
@basnijholt
basnijholt / seafile-raspberry.md
Last active December 17, 2017 14:37
Setting up seafile with encrypted disk on a Raspberry Pi on eduroam

Setting up seafile on a Raspberry Pi with stretch and an encrypted external drive

Install Raspbian stretch

  • download the image here
  • put the rasbian stretch image on an SD-card with Etcher
  • put a ssh file in the /boot folder by doing: cd /Volumes/boot/ and touch ssh
  • connect the Raspberry Pi to your router and ssh into it
  • run ssh-copy-id pi@<ip here>
  • change password with passwd
  • Expand file system, change hostname, set timezone, change Wi-Fi country, and set locale in sudo raspi-config
@basnijholt
basnijholt / install_conda_hpc05.sh
Last active December 8, 2017 12:25
Install conda with correct quantumtinkerer environments
#/bin/bash
# run this script with:
# nohup ~/Work/install_conda.sh > /dev/null 2>&1 &
export CONDA_DIR="${HOME}/miniconda3"
# Create a temporary folder
mkdir -p ~/tmp && cd ~/tmp
@basnijholt
basnijholt / email-signature.html
Created April 5, 2018 11:07
HTML email signature
<table border="0" width="300" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: 0 8px 0 0" valign="top" width="100"><img style="width: 100px; border-radius: 10%" src="http://nijholt.biz/stuff/me.png" alt="" width="100" /></td>
<td style="font-size: 1em; padding: 0 15px 0 8px" valign="top">
<table style="line-height: 1.4; font-family: Verdana, Geneva, sans-serif; font-size: 70%; color: #000001" border="0" cellspacing="0" cellpadding="0">
@basnijholt
basnijholt / nbviewer_alias.sh
Created May 8, 2018 12:24
upload notebook and get nbviewer link
nbviewer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho nbviewer /tmp/test.ipynb\ncat /tmp/test.ipynb | nbviewer test.ipynb"; return 1; fi
tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; (cat $tmpfile | sed s@https://@https://nbviewer.jupyter.org/urls/@g); rm -f $tmpfile; echo ""; }
@basnijholt
basnijholt / slurm_ipyparallel.md
Last active July 5, 2023 12:24
Using Slurm with ipyparallel

Using ipyparallel on the cluster

One time only

Create a parallel profile

ipython profile create --parallel --profile=slurm

cd into ~/.ipython/profile_slurm/

@basnijholt
basnijholt / slurm_jupyter.md
Created May 24, 2018 01:44
Jupyter notebook as Slurm job

Create slurm_jupyter.sbatch

#!/bin/bash
#SBATCH --nodes 1
#SBATCH --ntasks-per-node 20
#SBATCH --exclusive
#SBATCH --time 4:00:00
#SBATCH --mem-per-cpu 4000
#SBATCH --job-name jupyter
@basnijholt
basnijholt / run_simulation.py
Created May 24, 2018 16:49
`run_simulation` with ipyparallel
"""Common functions for doing stuff."""
from copy import copy
from datetime import timedelta
import functools
from glob import glob
from itertools import product
import os
import time
import subprocess