Skip to content

Instantly share code, notes, and snippets.

View lightyrs's full-sized avatar
🌒
ლ(▀̿̿Ĺ̯̿̿▀̿ლ)

Harris Novick lightyrs

🌒
ლ(▀̿̿Ĺ̯̿̿▀̿ლ)
View GitHub Profile
@lightyrs
lightyrs / rails-export-csv.rb
Created June 25, 2012 02:32 — forked from bcalloway/rails-export-csv.rb
Use FasterCSV to export an ActiveRecord object in Rails
### /config/environment.rb
config.gem 'fastercsv'
### /config/routes.rb
map.connect '/users/export', :controller => 'users', :action => 'export'
### /app/models/user.rb
# find all students and pass to controller export action for export to csv
def self.find_students
find_by_sql("select students.firstname, students.lastname, students.grade, students.homeroom, students.phone, students.email, students.relationship, users.firstname, users.lastname, accounts.school from students, users, accounts where students.user_id = users.id and accounts.id = users.account_id")
@lightyrs
lightyrs / aliases.sh
Created May 23, 2012 23:11
More aliases
# ps aux | ack {process_name}
function pq() { ps aux | ack $1; }
# cd {dir}; ls
function cdls() { cd $1; ls; }
@lightyrs
lightyrs / .railsrc
Created May 6, 2012 20:41 — forked from janlelis/.railsrc
13 Rails-specific hints for your rails 3 console.
# .railsrc for Rails 3, encoding: utf-8
# see http://rbjl.net/49-railsrc-rails-console-snippets
if !Rails.application then warn "Rails isn't loaded, yet... skipping .railsrc" else
# # #
def ripl?; defined?(Ripl) && Ripl.instance_variable_get(:@shell); end
# # #
# loggers
@lightyrs
lightyrs / _pm_irbrc.rb
Created May 6, 2012 20:37 — forked from inkdeep/_pm_irbrc.rb
Useful method to print an objects methods in an irb/console session.
# pm - Print methods of objects in irb/console sessions.
# Goes in ~./irbrc
#
begin # Utility methods
def pm(obj, *options) # Print methods
methods = obj.methods
methods -= Object.methods unless options.include? :more
filter = options.select {|opt| opt.kind_of? Regexp}.first
methods = methods.select {|name| name =~ filter} if filter
@lightyrs
lightyrs / grape.rb
Created April 23, 2012 01:56 — forked from sonymusic-d2c-pairs/grape.rb
Elegant example of declaring requires, modules, and autoloads for ruby lib in rails env
require 'rack'
require 'rack/builder'
module Grape
autoload :API, 'grape/api'
autoload :Endpoint, 'grape/endpoint'
autoload :MiddlewareStack, 'grape/middleware_stack'
autoload :Client, 'grape/client'
autoload :Route, 'grape/route'
autoload :Entity, 'grape/entity'
@lightyrs
lightyrs / hack.sh
Created March 31, 2012 20:41 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@lightyrs
lightyrs / ascii_money.txt
Created March 13, 2012 07:49
ASCII US Dollar Bills
http://www.retrojunkie.com/asciiart/money/bills.txt
_____________________________________________________________________
|.============[_F_E_D_E_R_A_L___R_E_S_E_R_V_E___N_O_T_E_]============.|
||%&%&%&%_ _ _ _ _ _ _ _ _ _ _ _ _ %&%&%&%&||
||%&%&%&/||_||_ | ||\||||_| \ (_ ||\||_(_ /\|_ |\|V||_|)|/ |\ \%&%&%||
||&%.--.}|| ||_ \_/| ||||_|_/ ,_)|||||_,_) \/| ||| ||_|\|\_||{.--.%&||
||%/__ _\ ,-----,-'____'-,-----, /__ _\ ||
||||_ / \| [ .-;"`___ `";-. ] ||_ / \|||
||| \| || """""""""" 1 `).'.'.'`_ _'. '.'.(` A 76355942 J | \| ||||
@lightyrs
lightyrs / config.ru
Created March 6, 2012 00:28
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@lightyrs
lightyrs / .gitignore
Created February 23, 2012 03:49
Ruby .gitignore
*.gem
*.rbc
.bundle
.config
coverage
InstalledFiles
lib/bundler/man
pkg
rdoc
spec/reports