Skip to content

Instantly share code, notes, and snippets.

Avatar

Maksim Rakitin mrakitin

  • Brookhaven National Laboratory
  • Upton, NY
View GitHub Profile
@mrakitin
mrakitin / switch-proxy.sh
Last active Oct 20, 2020
Switch ssh proxy configuration via a bash function
View switch-proxy.sh
switch_proxy() {
allowed_values=("o", "i")
cfg_file="$HOME/.ssh/config"
tmp_file="${cfg_file}_tmp"
ssh_base="ssh"
# ProxyCommand ssh -q -W %h:22 issh
current_pattern="ProxyCommand ssh -q -W %h:22 .${ssh_base}"
current_proxy=$(grep -e "${current_pattern}" ${cfg_file} | head -1 | tail -1 | awk '{print $NF}')
View gen-conda-packed-envs.sh
#!/bin/bash
# To be run as:
# $ docker run -it --rm -v $PWD:/build nsls2/debian-with-miniconda:v0.1.2 bash /build/gen-conda-packed-envs.sh
set -e
. /opt/conda/etc/profile.d/conda.sh
conda install conda -y
View deployment-steps.sh
#!/bin/bash
mkdir /opt/conda_envs/collection-2020-2.0rc1
cd /opt/conda_envs/collection-2020-2.0rc1
wget https://conda.nsls2.bnl.gov/conda/environments/collection-2020-2.0.tar.gz
tar -xvf collection-2020-2.0.tar.gz
conda activate $PWD
conda-unpack
View analysis-2019-3.0.1-ml-env-creation-log.txt
$ conda create -p /opt/conda_envs/analysis-2019-3.0.1-ml --clone analysis-2019-3.0.1-chx
$ conda activate /opt/conda_envs/analysis-2019-3.0.1-ml
$ pip install photutils[all] --upgrade
$ pip install astropy --upgrade
$ pip install dask[complete] --upgrade
$ pip install joblib --upgrade
$ chgrp -Rv xpcsml /opt/conda_envs/analysis-2019-3.0.1-ml/
$ chmod -Rv g+rwXs /opt/conda_envs/analysis-2019-3.0.1-ml/
View UM2020-centos_Vagrantfile
# -*-ruby-*-
Vagrant.configure("2") do |config|
# From https://app.vagrantup.com/metaswitch-its/boxes/centos7-min-xfce
config.vm.box = "metaswitch-its/centos7-min-xfce"
config.vm.hostname = "um2020"
config.vm.network "private_network", ip: "10.10.10.10"
config.vm.provider "virtualbox" do |v|
v.memory = 8192
v.cpus = 2
# Display the VirtualBox GUI when booting the machine
View convert_and_copy_refs.sh
#!/bin/bash
set -e
bib_src="$HOME/Brookhaven National Laboratory/NSLS-II SUF AI-ML - Beamline Optimization/LAB-20-2261_BL-opt.bib"
xml_src="$HOME/Brookhaven National Laboratory/NSLS-II SUF AI-ML - Beamline Optimization/LAB-20-2261_BL-opt.xml"
xml_dest="$HOME/Library/Containers/com.microsoft.Word/Data/Library/Application Support/Microsoft/Office/Sources.xml"
binary="/Applications/JabRef.localized/JabRef.app/Contents/MacOS/JabRef"
# Convert .bib file to .xml:
View alsmotor.py
"""
This was developed on 03/12/2020 during the ALS hackathon for the COSMIC beamline.
"""
from ophyd import PVPositioner, EpicsSignal, EpicsSignalRO, Component as Cpt
class ALSMotor(PVPositioner):
setpoint = Cpt(EpicsSignal, 'ao-MO:DVAL')
readback = Cpt(EpicsSignalRO, 'ai-MO:DRBV')
stop_signal = Cpt(EpicsSignal, 'bo-MO:STOP')
View bluesky_plan_with_custom_callback.py
import bluesky.plan_stubs as bps
import bluesky.plans as bp
from bluesky.callbacks.best_effort import BestEffortCallback
from bluesky.run_engine import RunEngine
from bluesky.utils import install_kicker
from databroker import Broker
from ophyd.sim import det, motor
RE = RunEngine()
db = Broker.named('temp')
View bluesky_plan.py
import bluesky.plan_stubs as bps
import bluesky.plans as bp
from bluesky.callbacks.best_effort import BestEffortCallback
from bluesky.run_engine import RunEngine
from bluesky.utils import install_kicker
from databroker import Broker
from ophyd.sim import det, motor
RE = RunEngine()
db = Broker.named('temp')
View superbowl-scores.py
import datetime
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
d = pd.read_html('http://www.espn.com/nfl/superbowl/history/winners', header=1)
scores = []
for s in d[0]['RESULT']:
parts = s.split(',')
You can’t perform that action at this time.