Skip to content

Instantly share code, notes, and snippets.

View avullo's full-sized avatar
🎯
Focusing

Alessandro Vullo avullo

🎯
Focusing
View GitHub Profile
@avullo
avullo / push_file_to_github_repo_branch.py
Created November 13, 2017 20:18
Push file update to GitHub repository using GitHub API in Python
import requests
import base64
import json
import datetime
def push_to_repo_branch(gitHubFileName, fileName, repo_slug, branch, user, token):
'''
Push file update to GitHub repo
@avullo
avullo / sample_files_from_directory.R
Last active December 6, 2017 00:57
R random sampling from (large) text files
## Randomly sample a given percentage of lines from files in a directory
## and write them out to a file
##
sampleFiles <- function(dir = './', ofname, perc = 1, append = TRUE, seed = 1234) {
## 'dir' is a characted vector of length 1 representing the name of the directory
## 'ofname' is a character vector of length 1 indicating the name of the output file
## 'append' is logical to tell wheter to append to sampled fraction to the output file
@avullo
avullo / file_number_of_empty_lines.R
Created November 13, 2017 19:45
R function to get the number of empty lines in a file
# count empty lines in a file
numberOfEmptyLines <- function(fname) {
if(!file.exists(fname)) {
stop(paste("Cannot read file ", fname, sep = " "))
}
as.integer(strsplit(try(system(paste("grep -cP '^$'", fname, sep = " "), intern = TRUE)), " +")[[1]][1])
}
@avullo
avullo / file_number_of_lines.R
Last active November 13, 2017 19:43
R function to get the number of lines in a file
# get the number of lines in a file
numberOfLines <- function(fname) {
if(!file.exists(fname)) {
stop(paste("Cannot read file ", fname, sep = " "))
}
as.integer(strsplit(try(system(paste("wc", fname, sep = " "), intern = TRUE)), " +")[[1]][2])
}
@avullo
avullo / Vagrantfile
Created March 12, 2014 10:30
Vagrant-vcloud on EBI Embassy cloud
dummy_box_url = "/home/avullo/work/vagrant-feature-jmg-vagrant-vcloud/vcloudTest/boxes/starman.box"
nodes = [
{ :hostname => "starman", :box => "starman", :box_url => dummy_box_url },
]
Vagrant.configure("2") do |config|
# vCloud Director provider settings
config.vm.provider :vcloud do |vcloud|