Skip to content

Instantly share code, notes, and snippets.

View amcooper's full-sized avatar
🐖
🐖

Adam Cooper amcooper

🐖
🐖
View GitHub Profile
@amcooper
amcooper / player_script.rb
Last active July 1, 2016 01:26
Basic Ruby code for launching a command-line MP3 player and playing a file
# Basic Ruby code for launching a command-line MP3 player and playing a file
command = "afplay fatal_wedding.mp3"
value = `#{command}`
# My own scripts
export PATH="~/bin:$PATH"
### RBENV
export PATH="$HOME/.rbenv/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
alias l='ls -alh'
export GIT_MERGE_AUTOEDIT=no
@amcooper
amcooper / .welcome_prompt.sh
Last active October 26, 2016 03:22
This welcome prompt prints stats on terminal load
#-------------------------------------------------------------------------------
# Welcome Prompt
# prints stats on terminal load
#-------------------------------------------------------------------------------
# welcome and unwelcome functions to toggle welcome_prompt are in .bash_prompt
WELCOME_PROMPT=true
welcome_msg() {
echo $(git --version)
# just add to the .profile or .bash_rc
# don't set prompt if this is not interactive shell
[[ $- != *i* ]] && return
color_default='\['`tput sgr0`'\]'
color_red='\['`tput sgr0; tput setaf 1`'\]'
color_green='\['`tput sgr0; tput setaf 2`'\]'
color_yellow='\['`tput sgr0; tput setaf 3`'\]'
color_light_blue='\['`tput sgr0; tput setaf 4`'\]'
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
# *) local and remote tag names
# 256 colors for vim
set -g default-terminal "screen-256color"
# Start window numbering at 1
set-option -g base-index 1
set-window-option -g pane-base-index 1
# Cycle panes with C-b C-b
unbind ^B
bind ^B select-pane -t :.+
" Make backspace behave in a sane manner.
set backspace=indent,eol,start
" Switch syntax highlighting on
syntax enable
" Enable file type detection and do language-dependent indenting
filetype plugin indent on
" Show line numbers
@amcooper
amcooper / project.rb
Created November 30, 2016 22:50
New code for title slugging
class Project
attr_accessor :title
def slug
@title.strip.downcase.gsub(/(&|&amp;)/, ' and ').gsub(/[\s\.\/\\]/, '-').gsub(/[^\w-]/, '').gsub(/[-_]{2,}/, '-').gsub(/^[-_]/, '').gsub(/[-_]$/, '')
end
end
@amcooper
amcooper / dbc-take-two.md
Last active July 11, 2017 02:39
Code challenge July 2017

dbc code challenge

rails new
rails generate scaffold User email password_digest
rails generate controller Sessions new create destroy
rails generate scaffold Album title user:references artist:references
rails generate scaffold Artist name
rails generate scaffold Song name album:references
rails generate scaffold Favorite user:references artist:references album:references song:references
@amcooper
amcooper / README.md
Last active August 2, 2017 00:59
Vigilant snippet no. 1

Snippet no. 1: the Tweet Controller (Ruby)

Introduction

Lesser Evil (lesser-evil-cli) is a hosted Ruby gem for the command line which applies a third-party, open-source sentiment analysis tool to collect negative-affect tweets regarding the 2016 U.S. Presidential candidates. The user chooses the candidate ("Trump" or "Clinton") and the negativity threshold ("angry" or "very angry").

What does it do?

The fetch_tweets method in the Tweet Controller is the primary engine of the application. It performs the following tasks:

  • Retrieves a batch of tweets. It calls (line 29) the get_batch method which makes GET requests to the Twitter Search API. The request includes search terms, desired number of results, and the maximum ID (i.e., the most recent ID from which to start the search)
  • Filters them according to sentiment. The if statement of line 36 tests for sentiment negativity and user-specified intensity
  • Creates a TweetSlim object from each matched tweet (line 37)
  • Prints each TweetSli