Skip to content

Instantly share code, notes, and snippets.

View masterdezign's full-sized avatar

masterdezign

View GitHub Profile
@masterdezign
masterdezign / Grad.hs
Last active December 10, 2018 13:23
A brief gradient descent illustration in Haskell
descent1D gradF iterN gamma x0 = take iterN (iterate _descend x0)
where
_descend gamma' x = x - gamma' * gradF x
-- Suppose, we have a function F(x) = (x - 3)^2.
-- Therefore, Grad F(x) = 2 * (x - 3).
gradF_test x = 2 * (x - 3)
main = print (descent1D gradF_test 10 gamma 0.0)
where gamma = 0.5
-- 0. Download x.data and y.dat from https://www.kaggle.com/masterdezign/iris-with-onehotencoded-targets
-- 1. Install stack (command line interface is marked by $):
-- $ wget -qO- https://get.haskellstack.org/ | sh
-- (alternatively, curl -sSL https://get.haskellstack.org/ | sh)
-- 2. Install open-blas from https://www.openblas.net/ (needed for hmatrix package)
-- 3. Run
-- $ stack --resolver lts-10.6 --install-ghc runghc --package hmatrix-0.18.2.0 Iris.hs
import Numeric.LinearAlgebra as LA
@masterdezign
masterdezign / cellular.py
Created January 21, 2019 10:37
Cellular automata in Python
#!/usr/bin/env python3
"""
Cellular automata in Python
"""
import sys
Z = '.'
O = '#'
@masterdezign
masterdezign / timelapse.sh
Created March 20, 2020 10:52
A video from images
# Concatenate images
ffmpeg -framerate 5 -pattern_type glob -i "*.jpg" output.mp4
# Compress
ffmpeg -i output.mp4 -vcodec libx265 -acodec aac -crf 23 output_compressed.mp4
@masterdezign
masterdezign / hasktorch.sh
Last active July 27, 2020 12:50
Hasktorch with Nix
# First of all make sure Nix is up and running https://nixos.org/nix
# Clone Hasktorch
git clone https://github.com/hasktorch/hasktorch.git
cd hasktorch
NIX_PATH="nixpkgs=https://github.com/NixOS/nixpkgs/archive/release-19.09.tar.gz"
nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix use hasktorch
Edit wpa_supplicant.conf and save it to the root of boot partition.
Replace the country code, ssid, and psk.
Full list of country codes: https://www.thinkpenguin.com/gnu-linux/country-code-list
On first boot, this file will be moved to /etc/wpa_supplicant/wpa_supplicant.conf where it may be edited later.
@masterdezign
masterdezign / basics.py
Created May 14, 2020 18:09
BCI 101: MNE workshop by David Haslacher
#%%
import os
import numpy as np
import mne
from mne.preprocessing import compute_current_source_density
# %matplotlib qt
# First, we need to load the data
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
@masterdezign
masterdezign / m5stickc-timer.ino
Last active May 24, 2020 18:04
M5StickC timer
/* NB: HAT speaker needs to be connected */
#include <M5StickC.h>
#include "esp32-hal-timer.h"
volatile int interruptCounter;
int totalInterruptCounter;
// https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
hw_timer_t * timer = NULL; //Created Hardware Timer
@masterdezign
masterdezign / eval.py
Last active August 13, 2021 11:47
Simple RL environment
import sys
import gym
from gym.envs.registration import register
from tensorforce.environments import Environment
from tensorforce.agents import Agent
if len(sys.argv) < 2:
print("Usage: python {} path/to/checkpoint".format(sys.argv[0]))
import pandas as pd
# .read_csv()
# .shape
# .head(N) .tail(N)
# .dtypes
# .loc[3, 'sepal_length'] .iloc
# .to_csv()
# pd.set_option('max_columns', 2)