Skip to content

Instantly share code, notes, and snippets.

Chris Roerig chris-roerig

Block or report user

Report or block chris-roerig

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
@chris-roerig
chris-roerig / ruby-2_6_0-docs-details.md
Last active Jun 9, 2019
Description level Ruby 2.6.0 documentation
View ruby-2_6_0-docs-details.md

ACL


    
Simple Access Control Lists.

Access control lists are composed of “allow” and “deny” halves to control access.  Use “all” or “*” to match any address.  To match a specific address use any address or address mask that IPAddr can understand.

Example:
@chris-roerig
chris-roerig / rdm.rb
Created Nov 8, 2018
Ruby drum machine
View rdm.rb
ruby -e "tempo=(60_000/(ARGV[0].to_i||100));start=0;current=(Time.now.to_f*1000).to_i;while true do current=(Time.now.to_f*1000).to_i;if((current-start)>tempo);start=current;print\"\a\";end;end" 120
@chris-roerig
chris-roerig / recipe.rb
Last active Oct 18, 2018
Automate vimrc and VundleInstall with Chef
View recipe.rb
remote_file "/home/chris/.vimrc" do
source "https://raw.githubusercontent.com/chris-roerig/dotfiles/master/vimrc"
owner "chris"
group "chris"
mode "0755"
end
directory "/home/chris/.vim/bundle/" do
owner "chris"
group "chris"
@chris-roerig
chris-roerig / rails_helper.rb
Created Mar 8, 2018
DatabaseCleaner rails_helper config
View rails_helper.rb
RSpec.configure do |config|
config.use_transactional_fixtures = false
# Use transactions by default
config.before :each do
DatabaseCleaner.strategy = :transaction
end
# For the javascript-enabled tests, switch to truncation, but *only on tables that were used*
config.before :each, :js => true do
@chris-roerig
chris-roerig / mathtools.R
Last active Jul 18, 2017
Simple R6 class in R
View mathtools.R
require("R6")
MathTool <-
R6Class("MathTool",
public = list(
data = NULL,
initialize = function(data = c()){
self$data <- data
},
odds = function() {
@chris-roerig
chris-roerig / initializer_paperclip.rb
Last active Jun 27, 2017
Rails 4 S3 Paperclip initializer
View initializer_paperclip.rb
# Gemfile
# gem "aws-sdk"
# gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68'
# config/initializers/paperclip.rb
Paperclip::Attachment.default_options.update({
storage: :s3,
s3_protocol: 'https',
@chris-roerig
chris-roerig / log_to.rb
Created Feb 13, 2017
Log to a specific file in Rails
View log_to.rb
# Logs to the specified file in the Rails log folder
#
# Usage:
# LogTo.file("tracking-numbers").info "log some data"
# or
# logger = LogTo.file("tracking-numbers")
# logger.info "this is saved in my tracking-numbers log"
class LogTo
def self.file(name)
return Rails.logger if Rails.env.test?
@chris-roerig
chris-roerig / ruby_macro_methds.rb
Last active Feb 21, 2019
How to add macro style methods to a rails model
View ruby_macro_methds.rb
# Rails Concern
# models/concerns/nicknameable.rb
module Nicknameable
extend ActiveSupport::Concern
included do
def self.nicknames(*args)
define_method("nicknames") { args }
end
nicknames
@chris-roerig
chris-roerig / timezone_from_coordinates.rb
Created Apr 25, 2016
Returns the time zone id for a given set of coordinates
View timezone_from_coordinates.rb
def timezone_from_coordinates(lat, long)
conn = Faraday.new(url: "https://maps.googleapis.com/maps/api/")
res = conn.get("timezone/json") do |req|
req.params["location"] = "#{lat},#{long}"
req.params["timestamp"] = Time.now.to_i
req.params["sensor"] = false
end
data = JSON.parse res.body
data["timeZoneId"]
@chris-roerig
chris-roerig / info.rb
Created Feb 8, 2016
Simple puts-er logger
View info.rb
# prints a message in the console.
# ##################
# this is my message
# ##################
def info(message, char = "#" )
len = `tput cols`.to_i
bar = -> { (len/ char.length).times { print char }; print "\n" }
(message.length / len).times { |n| message.insert(((n +1 ) * len), "\n") }
bar.call
You can’t perform that action at this time.