Skip to content

Instantly share code, notes, and snippets.

View mpilosov's full-sized avatar

Michael Pilosov mpilosov

View GitHub Profile
@mpilosov
mpilosov / seaborn_marginal_example.py
Last active February 2, 2018 01:34
Quick marginal plots with Seaborn
# Here we utilize scipy to draw samples from two distributions and plot the result.
import seaborn as sns
import numpy as np
import scipy.stats as sstats
x_dist = sstats.norm(loc=0, scale=2)
y_dist = sstats.uniform(loc=0, scale=1)
N = 10000
x_data = x_dist.rvs(N)

Manual Approach

Note: this procedure requires an .img file that you will be required to create from the .iso file you download.

Download the desired file. Convert the .iso file to .img using the convert option of hdiutil

hdiutil convert /path/to/ubuntu.iso -format UDRW -o /path/to/target.img  

Note: OS X tends to put the .dmg ending on the output file automatically.

@mpilosov
mpilosov / check_gitlog_commits.sh
Created January 27, 2018 06:43
check git log for commits, act on result.
#!/bin/bash
CHECKGITLOG=$(git log | head -3 | tail -1 | awk '{print $4;}')
TODAY=$(/bin/date | awk '{print $3}')
if [ $CHECKGITLOG -ne $TODAY ] # if you didn't do it today, act accordingly:
then
echo "HEY! YOU! DO YOUR WRITING!!! (repo synced more than a day ago)"
# Do whatever else. I like send_message.py (from my messager repo):
python messager/send_message.py 917xxxxxxx att "HEY BUM. GET WRITING. NOW."
fi
@mpilosov
mpilosov / kwd_fun_calls.py
Created January 27, 2018 06:36
keywording in python
import scipy.stats as sstats
def ev(*args, **kwds):
return sstats.norm(*args, **kwds)
kw = {'loc':2}
def kwrap(kwds):
return ev(**kwds)
print(kwrap(kw).rvs(3))

We'll be using nose for testing purposes.

The basic premise is simple. Write a file that imports solely the modules you want to test.

Writing your first nosetest

Write one test for each type-support that you want to be able to check. From this guide, we have the following example of ensuring that a user-defined function multiply operates the way it is intended to:

@mpilosov
mpilosov / python_setup.md
Last active October 27, 2019 04:04
Setting up Anaconda as a package manager, adding kernels to Jupyter.

How to Install Conda (a package manager)

Go download it from https://www.anaconda.com/download/ for your Linux/Windows/OSX

I like to use

wget http://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh

@mpilosov
mpilosov / image_example.py
Last active October 31, 2017 17:48
Images with Python
from matplotlib import pyplot as plt # the standard python plotting library
# installation instructions here: https://github.com/matplotlib/matplotlib
import numpy as np # math library for data-handling
# DEMO on random matrix to show how filtering based on pixel intensity works. How to make an image.
n = 20
I = np.random.random((n, n))
I[I>0.5] = 1 # highpass filter in two lines of code.
I[I<0.5] = 0
@mpilosov
mpilosov / GettingStartedWithGRBL.md
Last active May 26, 2023 19:22
Controlling Machines with GRBL

Instructions for a machine with GRBL already on it

My machine (basically this build: https://www.thingiverse.com/thing:1514145) has GRBL 0.9 : https://github.com/grbl/grbl/wiki/Configuring-Grbl-v0.9 The documents for newer version are up there too, obviously. It would definitely be good to get v1.1 working in order to learn the process of getting it on a fresh Arduino board. I'll outline the process of how to do that in the section below this one and fill in the details as I get around to figuring them out. Here's what I do know for sure though...

Sending GCode to the Machine

You can use any number of GUIs but the premise is always the same. Once the firmware is on your board, connect it via USB, power it on, and search in your /dev/ directory for your Arduino (type that into Terminal and start typing "tty" and then hit Tab until something shows up). If you have the Arduino software, use the drop down menus to identify an address like /dev/ttyusb#### or /dev/wchusbserial#### The numbers will be u

@mpilosov
mpilosov / writetexfiles.jl
Last active August 25, 2017 03:45
Write files to a grid of images in latex.
save_dir = "images/4D_2/"
QoI_list = [[12],[10], [7,16]]
std = 20
# image of the scatterplots.
portion = 0.32 # should be a hair less than 1/cols
cols = 3
rows = 2
# the following variable is how you want the row*cols images that will be in the figure to be ordered.
order = [ [1 3], [2 3], [1 4], [3 4], [1 2], [2 4] ] # part of the filenames (these are 2D scatterplots in 4D), serpentine column-dominant ordering. (top left to bot right)
for QoI_inds in QoI_list # loop through a list that differentiates the files from one another. each one of these is a different figure saved.
@mpilosov
mpilosov / plotting.py
Created August 25, 2017 03:07
Plotting example
import numpy as np
from matplotlib import pyplot as plt # imports plotting library, uses 'plt' as the handle. for help, google "matplotlib"
x = np.linspace(-1, 1, 100)
y = x.**2 + 2.*x + 1
plt.figure() # open a new figure (sometimes you see ax, fig = plt.figure() if people want to instantiate multiple figures.
plt.plot(x,y)
plt.xlabel("x axis")
plt.ylabel("y axis")