Skip to content

Instantly share code, notes, and snippets.

Kyle Carlson kyletcarlson

  • Kansas City, MO
Block or report user

Report or block kyletcarlson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kyletcarlson
kyletcarlson / tweets_controller.rb
Last active Dec 21, 2015
A Ruby on Rails controller action showing how to fetch a group of Tweets/followers/friends & send them to a view. You can also create Tweets with this controller & the Twitter API, but you'll need to ensure your callback URL is correct. Follow the documentation for that.
View tweets_controller.rb
class TweetsController < ApplicationController
before_action :create_client
def index
batch_size = 10
@twitter_handle = "dhh"
@tweets = @client.user_timeline(@twitter_handle).take(batch_size)
@friends = @client.friends(@twitter_handle).take(batch_size)
@kyletcarlson
kyletcarlson / VimMonokai.vim
Created Dec 14, 2013
My Vim color scheme based on Sublime Text's default scheme: Monokai.
View VimMonokai.vim
" Vim color file
" Converted from Textmate theme Monokai Refined using Coloration v0.3.2 (http://github.com/sickill/coloration)
set background=dark
" highlight clear
highlight Normal guibg=black guifg=white
if exists("syntax_on")
syntax reset
endif
View database.yml.example mysql2
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@kyletcarlson
kyletcarlson / ruby_benchmark_examples.rb
Created Dec 14, 2013
Three examples showing three of the main methods of Ruby's Benchmark class that's used to profile your code. Benchmark.measure at the most basic, Benchmark.benchmark allows you to run trials of different code blocks, and Benchmark.bmbm that helps you establish a baseline for your tests.
View ruby_benchmark_examples.rb
# http://www.ruby-doc.org/stdlib-2.0/libdoc/benchmark/rdoc/Benchmark.html
require 'benchmark'
# http://www.ruby-doc.org/stdlib-2.0.0/libdoc/bigdecimal/rdoc/BigMath.html
require 'bigdecimal/math'
# Set the number of iterations to run. The underscore here is used as a substitute for normal comma so Ruby interprets the number correctly.
iterations = 10
puts "\nCalculating pi #{iterations} times.\n\n"
View bluemix.rb
require 'asin'
require 'awesome_print'
ASIN::Configuration.configure do |config|
config.associate_tag = 'carlscorn-20'
config.key = 'AKIAJHAI7AL2VNXA4JWA'
config.secret = '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'
end
@kyletcarlson
kyletcarlson / ruby_github_gist_api.rb
Created Dec 11, 2013
A Ruby script demonstrating how to pull Gists from the GitHub Gist API.
View ruby_github_gist_api.rb
# Gem that wraps around the Gist API
# https://github.com/sinisterchipmunk/active-gist
require 'activegist'
# GitHub Gist API documentation:
# - http://developer.github.com/v3/gists/
# Set up credentials.
ActiveGist::API.username = "Your GitHub username"
ActiveGist::API.password = "Your GitHub password"
@kyletcarlson
kyletcarlson / ruby_web_scraping.rb
Created Dec 9, 2013
A Ruby web scraping script that visits a GitHub trending repos page, scrapes the data for the 25 repos, loads them into a CSV, and then reads from the CSV & creates a hash with each repo's data.
View ruby_web_scraping.rb
require 'mechanize'
require 'csv'
# Load up the trending Ruby repos on GitHub from the last month.
url_to_scrape = "https://github.com/trending?l=ruby&since=monthly"
# Snag the website with Mechanize & parse it into an XML document we can query.
page = Mechanize.new.get(url_to_scrape)
# Set the name of the CSV we'll create & load from.
file = "repo_data.csv"
@kyletcarlson
kyletcarlson / zappos_product_scraper.rb
Last active Jul 15, 2018
Small Ruby script that demonstrates how to use Mechanize to scrape some product details from an array of product URLs from Zappos.com
View zappos_product_scraper.rb
# http://nokogiri.org/Nokogiri/XML/Node.html#method-i-css
require 'mechanize'
require 'csv'
puts "Product Scraper!!!"
puts ' '
urls = [
"http://www.zappos.com/seavees-teva-universal-sandal-concrete",
@kyletcarlson
kyletcarlson / json_response_handling_ruby.rb
Created Dec 11, 2013
Ruby script that uses open-uri to fetch the contents of a JSON endpoint, uses the JSON gem to parse the string into a Ruby array & prints some of the records. This is the foundation for all web API requests, so feel free to use it in the future.
View json_response_handling_ruby.rb
# http://ruby-doc.org/stdlib-2.0.0/libdoc/open-uri/rdoc/OpenURI.html
require 'open-uri'
# https://github.com/flori/json
require 'json'
# http://stackoverflow.com/questions/9008847/what-is-difference-between-p-and-pp
require 'pp'
# Construct the URL we'll be calling
request_uri = 'http://localhost:3000/users.json'
request_query = ''
@kyletcarlson
kyletcarlson / deploy.rb
Created Dec 19, 2013
A sample Capistrano deploy.rb file I use as a base for all my projects. It's a straightforward & doesn't add much custom functionality besides symlinking my database.yml into my project from a folder outside of my application (considered good security practice).
View deploy.rb
require 'bundler/capistrano'
# Include this if you want to be able to set up different deployment stages (i.e. beta, stage, etc.)
# require 'capistrano/ext/multistage'
set :application, "example.com"
set :user, "linuxusername"
default_run_options[:pty] = true
set :use_sudo, true
You can’t perform that action at this time.