Skip to content

Instantly share code, notes, and snippets.

View maxehmookau's full-sized avatar

Max Woolf maxehmookau

View GitHub Profile
source 'https://rails-assets.org' do
gem 'rails-assets-pickadate'
gem 'rails-assets-select2'
gem 'rails-assets-underscore'
gem 'rails-assets-clipboard'
gem 'rails-assets-trix'
end
vagrant@precise64:/opt/substrakt/directorsuk$ bundle install
...
Using bundler 1.10.6
Using sprockets 3.5.1
Using sprockets-rails 2.3.3
Using rails 4.2.4
Using rails-assets-clipboard 1.5.5
Using rails-assets-jquery 2.1.4
Using rails-assets-cropper 2.2.0
@maxehmookau
maxehmookau / hierarchy_processor_after.rb
Created January 14, 2016 12:02
Before & After Ruby Metaprogramming
class HierarchyProcessor
attr_reader :input, :user
def initialize(input, user)
raise ArgumentError, "user expected User, was #{ user.class }" unless user.is_a?(User)
@input = JSON.parse(input)
@user = user
end
class HierarchyProcessor
attr_reader :input, :user
def initialize(input, user)
raise ArgumentError, "user expected User, was #{ user.class }" unless user.is_a?(User)
@input = JSON.parse(input)
@user = user
end
def service_groups
ServiceGroup.where(id: @input['service_groups'].map{ |s| s['id'] })
end
def locations
------------------- ----------------------
Location.where(id: @input['locations'].map{ |s| s['id'] })
------------------- ----------------------
end
def output_100
puts 100
end
# is exactly the same as ->
define_method(:output_100) do
puts 100
end
[:output_100, :output_200].each do |i|
define_method(i) do
puts i.to_s.split('_')[1]
end
end
class HierarchyProcessor
attr_reader :input, :user
def initialize(input, user)
raise ArgumentError, "user expected User, was #{ user.class }" unless user.is_a?(User)
@input = JSON.parse(input)
@user = user
end
@maxehmookau
maxehmookau / nginx.conf
Created March 1, 2016 15:27
Secure nginx config
server {
listen 80;
listen [::]:80;
listen 443 default ssl;
server_name YOURDOMAIN.com;
if ($ssl_protocol = "") {
rewrite ^ https://$server_name$request_uri? permanent;
}
@maxehmookau
maxehmookau / example.rb
Created April 21, 2016 09:19
HTTParty GET Request where two parameters have the same key
include HTTParty
query = {}
query["x"] = ['value1', 'value2']
response = HTTParty::Basement.get(__URL__, query: query,
query_string_normalizer: HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER)