Skip to content

Instantly share code, notes, and snippets.

View johnrc's full-sized avatar

John Cragun johnrc

View GitHub Profile
@johnrc
johnrc / app.rb
Created April 26, 2014 14:59 — forked from hendrikswan/app.rb
require 'sinatra'
require 'mongoid'
require 'json'
require "sinatra/reloader" if development?
Mongoid.load!("mongoid.yml")
class Price
include Mongoid::Document
@johnrc
johnrc / bower-proxy-windows.md
Last active August 29, 2015 14:01
Setting up bower behind a proxy on Windows

Steps for installing and using bower behind a proxy:

Install git, node and add C:\Program Files (x86)\Git\bin to %path% Then run the following:

set http_proxy=http://<username>:<password>@<host>:<port>/
set https_proxy=http://<username>:<password>@<host>:<port>/
npm install -g bower

Or you can add the following to your .bowerrc file in %userprofile% or in your project

@johnrc
johnrc / r-commands.md
Last active August 29, 2015 14:02
Useful commands for R

Installing packages

Install package and dependencies to a specific location. If you want the binaries cached, use destdir="/Rbins" option. If you want the package(s) installed to a specific location, use lib="~/Rlibs". The default location on Windows is %userprofile%\Documents\R\win-library\3.0.

install.packages("<package>", dependencies=NA, repos="http://cran.us.r-project.org")
R CMD INSTALL <package> -l ~/Rlibs

On Mac it would be something like

install.packages("<package>", dependencies=NA, type="mac.binary")
# 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'),
@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
@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.
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 / 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

@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_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: "