Skip to content

Instantly share code, notes, and snippets.

@paddy74
paddy74 / fileCounter.sh
Last active December 24, 2017 00:41
Count the number of words, sentences, and average number of words per sentence in a text file. Created for CS252 at Old Dominion University.
#!/bin/sh
for f in "$@"
do
w=`cat "$f" | sed "s/ */\\n/g" | sed "s/[^a-zA-Z0-9]//g" | sed "s/[0-9]*//g" | sed "/^$/d" | wc -w`
s=`cat "$f" | tr -d " \t\n\r" | sed "s/\./\\n/g" | sed "s/\?/\\n/g" | sed "s/\!/\\n/g" | wc -l`
z=$(expr "$w" / "$s")
echo $f:
echo " "$w words
echo " "$s sentences
@paddy74
paddy74 / Preferences.sublime-settings
Last active January 9, 2019 16:51
My user preferences for Sublime Text and vscode
// Sublime Text settings
{
"auto_complete_commit_on_tab": true,
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"default_line_ending": "unix",
"detect_indentation": true,
"font_size": 13,
"ignored_packages":
[
"Vintage"
@paddy74
paddy74 / my_git-labels.json
Created March 27, 2018 02:25
My preferred label setup. Uses git-label at https://github.com/jasonbellamy/git-label
[
{ "name": "Priority: Low", "color": "#009800" },
{ "name": "Priority: Medium", "color": "#fbca04" },
{ "name": "Priority: High", "color": "#eb6420" },
{ "name": "Priority: Critical", "color": "#e11d21" },
{ "name": "Status: Abandoned", "color": "#000000" },
{ "name": "Status: Accepted", "color": "#009800" },
{ "name": "Status: Available", "color": "#bfe5bf" },
{ "name": "Status: Blocked", "color": "#e11d21" },
{ "name": "Status: Completed", "color": "#006b75" },
@paddy74
paddy74 / build_3dslicer
Last active July 20, 2018 18:23
Single script to build 3D Slicer on Ubuntu 16.04
#!/bin/bash
# https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions
# Install prerequisites
sudo apt install subversion git-core git-svn
sudo apt install build-essential libx11-dev libxt-dev libgl1-mesa-dev libosmesa6-dev libglu1-mesa-dev libfontconfig1-dev libxrender-dev libncurses5-dev
sudo apt install cmake
sudo apt install libgstreamer-plugins-base1.0-dev # qt5
# Checkout
@paddy74
paddy74 / install_povray
Created July 18, 2018 23:28
Install POV-ray
#!/bin/sh
# If boost not found install libboost-all-dev
# If unable to find libpng12-dev use sudo apt-add-repository "deb http://us.archive.ubuntu.com/ubuntu/ xenial main universe" && sudo apt update && sudo apt install libpng12-dev
sudo apt-get install libboost-dev zlib1g-dev libpng12-dev libjpeg8-dev libtiff5-dev libopenexr-dev autoconf
git clone https://github.com/POV-Ray/povray.git
cd unix/
source ./prebuild.sh
@paddy74
paddy74 / install_prolog
Last active July 18, 2018 23:29
Install SWI-Prolog
#!/bin/sh
sudo apt-add-repository ppa:swi-prolog/stable
sudo apt update
sudo apt install swi-prolog
@paddy74
paddy74 / np_convolve2d.py
Last active August 21, 2018 21:41
2D convolution using only numpy
def np_convolve2d(a, v, mode='valid', keep_dims=False): # mode='valid'
"""Convolve an image with filter_n using valid mode
In valid mode the output consists only of those elements that do not rely on the zero-padding.
# TODO: full and same modes
Parameters
----------
a : (N,) array_like
First one-dimensional input array.
v : (M,) array_like
@paddy74
paddy74 / concatenate_array_files.py
Created August 28, 2018 19:10
Create a memory-mapped array comprised of the concatenation of every .npy file in a directory
def concatenate_array_files(src_dir, file_name):
"""Create a memory-mapped array comprised of the concatenation of every
.npy file in a directory
Parameters
----------
src_dir : str
Directory of 2D .npy arrays with matching feature counts
file_name : str
File in which to save the concatenated arrays
@paddy74
paddy74 / utils.py
Last active November 7, 2018 18:05
Some utility methods
from itertools import islice, repeat, chain, combinations
import random
def contents_as_str(iterable, delim=' '):
"""Provides the contents of an iterable as a string.
Parameters
----------
iterable : Iterable
@paddy74
paddy74 / link_ssh_keys.sh
Last active May 22, 2019 01:49
Set up ssh authentication with a server from user side