Skip to content

Instantly share code, notes, and snippets.

View johnrc's full-sized avatar

John Cragun johnrc

View GitHub Profile
@johnrc
johnrc / mac_bootable_drive.sh
Created March 26, 2015 01:20
Command to create bootable Mac OS X installer
#!/usr/bin/env bash
# Must run as sudo and assumes the following:
# 1. your drive has been formatted with the name of "Untitled"
# 2. you've downloaded Yosemite from Apple store
/Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia \
--volume /Volumes/Untitled \
--applicationpath /Applications/Install\ OS\ X\ Yosemite.app
--nointeraction
@johnrc
johnrc / gist:956d3ba78d4539caf3a3
Last active August 29, 2015 14:15
Basic Apache virtual host configuration
# http://www.rackspace.com/knowledge_center/article/how-to-serve-multiple-domains-using-virtual-hosts
# Uncomment this line from /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
# Create multiple files for each vhost or put them all in one
# They just need to be named with *.conf to be picked up
<VirtualHost *:80>
ServerName example.org
ServerAlias *.example.org
ServerAdmin webmaster@example.org
@johnrc
johnrc / python_scraper.py
Last active August 29, 2015 14:10
Scrape melskitchencafe.com for recipes
# Before running this script, install requests, beautifulsoup4
import requests as req
from bs4 import BeautifulSoup
url = "http://www.melskitchencafe.com/vanilla-buttermilk-cupcakes-and-fantastic-easy-buttercream-frosting/"
html = req.get(url)
soup = BeautifulSoup(html.text)
print "This is a recipe for: "
@johnrc
johnrc / PrintDependencyTree
Last active August 31, 2022 15:52
Print dependency tree for R package
## function getDependencyTree()
# Only parameter that's required is the package you want a dependency tree for
getDependencyTree <- function(pack, i = -1, depLevel = c("Depends", "Imports", "LinkingTo"), availablePackages = available.packages()) {
if(i == -1) cat(pack, "\n")
i <- i + 1
packages <- unlist(tools::package_dependencies(pack, availablePackages, which = depLevel))
for(pkg in packages) {
for(n in 0:i) {
cat(" ")
}
@johnrc
johnrc / convert-images
Last active August 29, 2015 14:06
Tiny bash script to convert images to lesser quality
# `brew install imagemagick` will give access to `convert`
# This loops through the current directory and converts
# each file to 50% the quality
for x in *
do
convert $x -quality 50 ~/noedit/$x
done
@johnrc
johnrc / python-commands.md
Last active August 29, 2015 14:05
Python command line cheatsheet

Install with setuptools with one or two steps: python setup.py build and python setup.py install. To uninstall follow the SO question here, which suggests

python setup.py install --record files.txt
cat files.txt | xargs rm -rf

RedHat has a thing called software collections that lets other versions of Python (and other languages or databases) be installed.

yum install python27
scl enable python27 bash

which python

This article was a huge help: http://evadeflow.com/2010/09/easy_install-through-a-proxy-server/
Basically, what I learned is that you need to set both the http_proxy and https_proxy for setuptools easy_install to work.
It's worth mentioning I'm using this version of Python 2.7 on Windows 7 64-bit: http://www.activestate.com/activepython
From the Windows command prompt, I first set the two environment variables:
c:\> set http_proxy=<user>:<password>@<proxy_ip_address>:<port>
@johnrc
johnrc / package.R
Created June 20, 2014 16:59 — forked from jbryer/package.R
#' Simplified loading and installing of packages
#'
#' This is a wrapper to \code{\link{require}} and \code{\link{install.packages}}.
#' Specifically, this will first try to load the package(s) and if not found
#' it will install then load the packages. Additionally, if the
#' \code{update=TRUE} parameter is specified it will check the currently
#' installed package version with what is available on CRAN (or mirror) and
#' install the newer version.
#'
#' @param pkgs a character vector with the names of the packages to load.
@johnrc
johnrc / yum-commands.md
Last active August 29, 2015 14:02
Useful commands for yum

General Yum Commands

yum search <whatever>
yum install <package>
yum autoremove <package> //good for removing dependencies
yum remove <package> //only removes package and others that depend on it
yum upgrade //update and remove any unneeded packages
yum clean expire-cache //refresh the cache, similar to apt-get update
# Looks in the CRAN archive for the specified package and version. If
# the specified version is NULL or the same as the most recent version
# of the package, this function simply calls install.packages(). Otherwise,
# it looks at the list of archived source tarballs and tries to install
# an older version instead.
install.package.version <- function(
package,
version = NULL,
repos = getOption('repos'),