Skip to content

Instantly share code, notes, and snippets.

@LLCampos
LLCampos / SharedResourceSpec.scala
Created May 15, 2021 09:21
Scala trait that gives you the ability to share a Cats Effect's Resource across a specs2 suite's tests. Acquires the resource in the beginning of the suite and releases them in the end.
import cats.effect.IO
import cats.effect.kernel.Resource
import cats.effect.unsafe.implicits.global
import org.specs2.mutable.Specification
import org.specs2.specification.core.Fragments
import org.specs2.specification.dsl.ActionDsl
import scala.concurrent.duration._
// This taken from https://github.com/http4s/http4s/blob/bd9a64d95a9d280f46fa0ce3ebd80f741ef96bb0/specs2/src/test/scala/org/http4s/Http4sSpec.scala
@LLCampos
LLCampos / ssh-to-list-of-servers.sh
Created February 6, 2021 11:55
ssh to all servers in a list, each in a different tab
#!/bin/bash
# Replace here
servers=(server1 server2 server3)
for server in "${servers[@]}"; do
x-terminal-emulator --new-tab -e "ssh $server"
done
@LLCampos
LLCampos / amITalkingAboutMeAgain.js
Created May 14, 2019 19:58
Tapermonkey user script. An experiment on improving chat conversations. Changes the color of Messenger or WhatsApp text box every time I start to write about myself.
// ==UserScript==
// @name Am I talking about me again?
// @namespace
// @version 0.1
// @description Find references to myself in messaging web apps
// @author
// @match
// @grant none
// ==/UserScript==
@LLCampos
LLCampos / record_hipchat_voice.py
Last active June 9, 2018 19:02
Records HipChat video calls
#!/usr/bin/env python3
import os
import subprocess
from time import sleep, time
save_folder = "/home/lcampos/Dropbox/BetterConversationsRecordings"
speakers_monitor_stream = "alsa_output.pci-0000_00_1f.3.analog-stereo.monitor"
class Recording:
@LLCampos
LLCampos / pre-commit.sh
Last active April 20, 2020 07:25
pre-commit hook for Maven multi-project repositories - Build and run tests for each Maven project for which there are staged files
#!/bin/bash
# Install with:
# ln -s ../../pre-commit.sh .git/hooks/pre-commit
# Inspired by:
# https://gist.github.com/arnobroekhof/9454645
function pop_stash {
STASHES=($(git stash list))
@LLCampos
LLCampos / obo-to-words.py
Created April 12, 2017 14:07
Extract, form a .obo file, all names and synonyms into a .txt file
import re
input_file_name = 'hp.obo'
output_file_name = 'hpo.txt'
# Read the whole .obo file into a string
with open(input_file_name) as f:
obo_string = f.read()
# This will include all entity names, including main names and synonyms
@LLCampos
LLCampos / convert_noble_coder_annots_to_webanno_tsv.py
Created February 9, 2017 16:12
Converts annotations output from Noble Coder to WebAnno TSV 2 format
# coding: utf-8
import os
import re
import nltk.data
"""Converts annotations output from Noble Coder (http://noble-tools.dbmi.pitt.edu/) to
WebAnno TSV 2 format (https://webanno.github.io/webanno/releases/3.0.1/docs/user-guide.html#sect_webannotsv)
@LLCampos
LLCampos / cc_number_generator.py
Created December 20, 2016 13:49
My implementation of a random generator of valid credit card numbers
from numpy import random
def luhn_checksum(n):
"""Calculates Luhn's Checksum of a number. n must be a string.
Check Wikipedia to understand the algorithm."""
even = 0
odd = 1
@LLCampos
LLCampos / singularize.py
Created November 15, 2016 17:13
Singularize (change to the singular form) all the words in a piece of text
from pattern.en import singularize
from nltk import word_tokenize
def singularize_all_words(text):
tokenized_text = word_tokenize(text)
tokenized_singularized_text = map(singularize, tokenized_text)
singularized_text = ' '.join(tokenized_singularized_text)
return singularized_text
@LLCampos
LLCampos / extract_radlex_terms.py
Last active November 6, 2016 12:46
Given an OWL file of the RadLex ontology, extract all the class/terms preferred names into a file
from lxml import etree
radlex_tree = etree.parse('Radlex3.13.1.owl').getroot()
# Get all the term names of the Ontology, in a list.
all_terms = radlex_tree.xpath('//x:Preferred_name/text()',
namespaces={'x': radlex_tree.nsmap[None]})
with open('radlex_all_terms_names.txt', 'w') as f:
for term in all_terms: