Skip to content

Instantly share code, notes, and snippets.

View hernamesbarbara's full-sized avatar

austin hernamesbarbara

View GitHub Profile
@hernamesbarbara
hernamesbarbara / seeds.rb
Created February 19, 2012 17:10
Create Admin User in Ruby on Rails Application using rake db:seed
#db/seeds.rb
# Run 'rake db:seed' from terminal to create an Admin User in your database
#Seed DB with at least 1 Admin User
admin=User.new({ name: "Admin User", email: 'admin@rubyonrails.com',
password: 'password', password_confirmation: 'password'})
admin.toggle!(:admin)
@hernamesbarbara
hernamesbarbara / .ackrc
Created February 26, 2012 20:19
Example configuration for using Ack to search file tree
#ack is a tool like grep, designed for programmers with large trees of heterogeneous source code
#to install ack, see http://betterthangrep.com/
#to use ack, launch terminal (mac osx) and type 'ack <some_keywords>'
#ack will search all files in the current directory & sub-directories
#here's how I have my config file setup. this file is located on mac osx here
# ~/.ackrc
# Always sort the files
@hernamesbarbara
hernamesbarbara / .bash_profile
Created February 29, 2012 04:59
bash_profile with terminal colors and useful aliases
#!/bin/bash
export TERM=xterm-color
export CLICOLOR=1
export GREP_OPTIONS='--color=auto'
# export LSCOLORS=Exfxcxdxbxegedabagacad
export LSCOLORS=gxfxcxdxbxegedabagacad # Dark lscolor scheme
# Don't put duplicate lines in your bash history
export HISTCONTROL=ignoredups
# increase history limit (100KB or 5K entries)
export HISTFILESIZE=100000
@hernamesbarbara
hernamesbarbara / .inputrc
Created February 29, 2012 05:03
search bash history quickly
#!/bin/bash
set completion-ignore-case on
#use up arrow to search history backwards
"\e[A": history-search-backward
"\e[B": history-search-forward
$if Bash
Space: magic-space
$endif
@hernamesbarbara
hernamesbarbara / PostgreSQL_Query.R
Created July 6, 2012 13:11
how to connect to a postgreSQL database from R
library(RPostgreSQL) #import the library
driver <- dbDriver('PostgreSQL') #define the database driver
db <- dbConnect(driver, host='foobar_host', #set the host to the postgreSQL IP or alias
user='foo_bar', #input username
password='my_secret_code', #input your password
dbname='my_gp_db') #input the name of the databse
myquery <- "SELECT
@hernamesbarbara
hernamesbarbara / google_regex.md
Created October 10, 2012 18:39
google regular expression helpers
#extract words in parens from a string
value.match(/(.+)\((.*)\)(.+)/)[1].split(' ')[1]

#replace the following characters with empty string:  , .  - ( )
toUppercase(value).replace(/\,|\.|\-|\(|\)|\[|\]/, '')
@hernamesbarbara
hernamesbarbara / pandas_na_cheatsheet.py
Created October 31, 2012 15:42
handle NA values in pandas
#/usr/bin/env python
# Handling NA values in pandas
import pandas as pd
# replace all NA values with your own missing value
my_data_frame['my_column'].fillna('MY_MISSING_VAL')
# return a subset of your dataframe
@hernamesbarbara
hernamesbarbara / select_rows_pandas.py
Created January 11, 2013 16:53
selecting data in pandas
import numpy as np
import pandas as pd
# look at free reports
free = df[df.report_name.isin(free)]
# look at paid reports only
paid = df[df.report_name.apply(lambda x: x not in free)]
from yhat import Yhat, BaseModel
from sklearn import datasets
from sklearn.svm import SVC
class IrisModel(yhat.BaseModel):
def transform(self, data):
data = [
data['SepalLength'],
data['SepalWidth'] / 2.0,
data['PetalLength'],
pip install yhat