Skip to content

Instantly share code, notes, and snippets.

View mscoutermarsh's full-sized avatar

Mike Coutermarsh mscoutermarsh

View GitHub Profile
@mscoutermarsh
mscoutermarsh / hcti.rb
Last active September 3, 2018 16:00
Ruby - convert html/css to an image
require "httparty"
# Retrieve your user id and api key from the Dashboard https://htmlcsstoimage.com/dashboard
auth = { username: 'user_id', password: 'api_key' }
html = "<div class='ping'>Pong ✅</div>"
css = ".ping { padding: 20px; font-family: 'sans-serif'; }"
image = HTTParty.post("https://hcti.io/v1/image",
body: { html: html, css: css },
basic_auth: auth)
@mscoutermarsh
mscoutermarsh / .travis.yml
Created October 29, 2017 17:45
example travis file
language: ruby
rvm:
- 2.4.1
env:
- DB=postgresql
script:
- RAILS_ENV=test bundle exec rake --trace db:create
- RAILS_ENV=test bundle exec rake --trace db:migrate
- bundle exec rake db:test:prepare
- bundle exec rspec
@mscoutermarsh
mscoutermarsh / .rubocop.yml
Created October 29, 2017 17:42
Example rubocop file
AllCops:
Exclude:
- db/**/*
- Gemfile
- vendor/**/*
- config/environments/*
- bin/**/*
Rails:
Enabled: true
@mscoutermarsh
mscoutermarsh / premailer.rb
Last active September 5, 2017 00:16
premailer
email = Premailer::Rails::Hook.perform(YourMailer.some_email(blah_blah))
# get the body
email.html_part.body.to_s
# text
email.text_part.body.to_s
@mscoutermarsh
mscoutermarsh / purge_cache.rb
Created November 15, 2016 18:25
Example Ruby for purging imgix cache
# usage: Set env variable IMGIX_API_KEY to your api key
# Need to add httparty to your gemfile
#
# Cdn::Purge.cache.call('urlhere')
class Cdn::PurgeCache
include HTTParty
API_KEY = ENV.fetch('IMGIX_API_KEY'.freeze)
base_uri 'https://api.imgix.com/v2'.freeze
class << self
@mscoutermarsh
mscoutermarsh / travis.yml
Created September 24, 2016 19:33
Example
language: ruby
rvm:
- 2.2.4
before_install: gem update --remote bundler
install:
- bundle install --retry=3
script:
- bundle exec rspec
- bundle exec rubocop --config .rubocop.yml
services: "-postgresql"
@mscoutermarsh
mscoutermarsh / tmux.md
Last active September 21, 2016 19:32
how i setup/navigate tmux panes

Hey!

I tried to make a video :): http://cloud.mikeasaur.us/2Y2I2x3h0O0v

As I write this, I'm realizing it's super confusing at first. So I hope this makes sense.

From a new terminal, I first start a new tmux session

tmux new -s mike

@mscoutermarsh
mscoutermarsh / stripe_testing_token.md
Last active September 7, 2016 19:52
Ruby - create Stripe token for testing

If you need to create a Stripe token for testing. Do this.

Stripe::Token.create(
  :card => {
    :number => "4242424242424242",
    :exp_month => 9,
    :exp_year => 2017,
    :cvc => "314"
 },
some_data = [{ type: 'dog', name: 'Fido' },
{ type: 'dog', name: 'Ruby' },
{ type: 'cat', name: 'Fuzzy' }]
some_data.partition { |pet| pet[:type] == 'cat' }
=> [[{:type=>"cat", :name=>"Fuzzy"}],
[{:type=>"dog", :name=>"Fido"}, {:type=>"dog", :name=>"Ruby"}]]
require 'csv'
require 'pry'
orders = CSV.read('orders.csv', headers: true)
output = open('output.csv', 'w')
output.truncate(0)
output.write("order_id, quantity, shipping_address\n")