Skip to content

Instantly share code, notes, and snippets.

@nashid
nashid / sequence.scala
Created March 4, 2019 23:50 — forked from cb372/sequence.scala
Using Cats Traverse to turn a List of Try into a Try of List
Welcome to the Ammonite Repl 0.8.0
(Scala 2.11.8 Java 1.8.0_91)
@ import scala.util.Try
import scala.util.Try
@ val listOfTries: List[Try[String]] = List(Try("a"), Try("b"), Try("c"))
listOfTries: List[Try[String]] = List(Success("a"), Success("b"), Success("c"))
// I have a List[Try[String]] but I actually want a Try[List[String]].
@nashid
nashid / MonadAndFs2Ops.md
Created March 6, 2019 19:48 — forked from Daenyth/MonadAndFs2Ops.md
Cheat sheet for common cats monad and fs2 operation shapes
Operation Input Result Notes
map F[A] , A => B F[B] Functor
apply F[A] , F[A => B] F[B] Applicative
(fa, fb, ...).mapN (F[A], F[B], ...) , (A, B, ...) => C F[C] Applicative
(fa, fb, ...).tupled (F[A], F[B], ...) F[(A, B, ...)] Applicative
flatMap F[A] , A => F[B] F[B] Monad
traverse F[A] , A => G[B] G[F[A]] Traversable; fa.traverse(f) == fa.map(f).sequence; "foreach with effects"
sequence F[G[A]] G[F[A]] Same as fga.traverse(identity)
. . . .
@nashid
nashid / .gitconfig
Last active February 22, 2021 08:18 — forked from lifuzu/.gitconfig
Three levels of GIT config
# There are 3 levels of git config: global, project, and system.
# global: Global configs are available for all projects for the current user and stored in ~/.gitconfig.
# project: Project configs are only available for the current project and stored in .git/config in the project's directory.
# system: System configs are available for all the users/projects and stored in /etc/gitconfig.
# Create a global config
$ git config --global user.name "John Doe"
# Create a project specific config, you have to execute this under the project's directory.
@nashid
nashid / private_fork.md
Created June 23, 2021 04:35 — forked from 0xjac/private_fork.md
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare git@github.com:usi-systems/easytrace.git

@nashid
nashid / install_packages_conda.sh
Last active June 24, 2021 06:56 — forked from luiscape/install_packages.sh
Install Python dependency packages from requirements.txt Using conda.
#
# Original solution via StackOverflow:
# http://stackoverflow.com/questions/35802939/install-only-available-packages-using-conda-install-yes-file-requirements-t
#
#
# Install via `conda` directly.
# This will fail to install all
# dependencies. If one fails,
# all dependencies will fail to install.
@nashid
nashid / condaenv.txt
Last active June 24, 2021 07:12 — forked from pratos/condaenv.txt
To package a conda environment (Requirement.txt and virtual environment)
# For Windows users# Note: <> denotes changes to be made
#Create a conda environment
conda create --name <environment-name> python=<version:2.7/3.5>
#To create a requirements.txt file:
conda list #Gives you list of packages used for the environment
conda list -e > requirements.txt #Save all the info about packages to your folder
@nashid
nashid / tmux_vs_screen.md
Created July 15, 2021 20:06 — forked from P7h/tmux_vs_screen.md
tmux vs screen commands

tmux vs. screen commands


Action tmux screen
start a new session tmux
tmux new
tmux new-session
screen
start a new session with a name tmux new -s name screen -S name
re-attach a detached session tmux attach
tmux attach-session
screen -r
re-attach a detached session with a name tmux attach -t name
tmux a -t name
screen -r name
re-attach an attached session (detaching it from elsewhere) tmux attach -dtmux attach-session -d screen -dr
@nashid
nashid / .md
Created September 23, 2021 17:02 — forked from rahulrajaram/.md
Python: Write to a file from multiple threads

I recently came across the need to spawn multiple threads, each of which needs to write to the same file. Since the file will experience contention from multiple resources, we need to guarantee thread-safety.

NOTE: The following examples work with Python 3.x. To execute the following programs using Python 2.7, please replace threading.get_ident() with thread.get_ident(). As a result, you would need to import thread and not threading.

  1. (The following example will take a very long time). It will create 200 threads, each of which will wait until a global lock is available for acquisition.
# threading_lock.py
import threading
@nashid
nashid / PBS_sample.sh
Created January 10, 2022 22:53 — forked from mathsam/PBS_sample.sh
Sample PBS script
# Sample PBS job script
#
# Copy this script, customize it and then submit it with the ``qsub''
# command. For example:
#
# cp pbs-template.sh myjob-pbs.sh
# {emacs|vi} myjob-pbs.sh
# qsub myjob-pbs.sh
#
# PBS directives are fully documented in the ``qsub'' man page. Directives