Skip to content

Instantly share code, notes, and snippets.

@rafalcode
rafalcode / source_lines.R
Created June 23, 2023 22:12 — forked from christophergandrud/source_lines.R
Source specific lines from a file in R
#' Source specific lines in an R file
#'
#' @param file character string with the path to the file to source.
#' @param lines numeric vector of lines to source in \code{file}.
source_lines <- function(file, lines){
source(textConnection(readLines(file)[lines]))
}
@rafalcode
rafalcode / bash_aws_jq_cheatsheet.sh
Created April 23, 2019 15:36 — forked from lukeplausin/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
#!/usr/bin/env python2.7
import os, sys, urllib2
if os.environ.get('http_proxy') is None:
os.environ['http_proxy']="http://172.25.64.1:3128"
resp0=urllib2.urlopen("http://rest.kegg.jp/link/ko/ec:3.1.11.1")
output=resp0.read()
print output,