Skip to content

Instantly share code, notes, and snippets.

View beneggett's full-sized avatar

Ben Eggett beneggett

View GitHub Profile
@beneggett
beneggett / cheatsheet.rb
Created January 13, 2023 16:25 — forked from mabenson00/cheatsheet.rb
Rails ActiveRecord JSON cheatsheet
# Basic key operators to query the JSON objects :
# #> : Get the JSON object at that path (if you need to do something fancy)
# -> : Get the JSON object at that path (if you don't)
# ->> : Get the JSON object at that path as text
# {obj, n} : Get the nth item in that object
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
# Date
# date before today
@beneggett
beneggett / sidekiq.service
Created November 11, 2022 20:53 — forked from sj26/sidekiq.service
systemd unit files for multiple sidekiq workers
[Unit]
Description=Sidekiq workers
# start as many workers as you want here
Wants=sidekiq@1.service
Wants=sidekiq@2.service
# ...
[Service]
Type=oneshot
ExecStart=/bin/true
@beneggett
beneggett / multi_provider_saml_handler.rb
Created August 19, 2019 20:13 — forked from jturkel/multi_provider_saml_handler.rb
How to configurate omniauth-saml to work with multiple identity providers based on a dynamic URL path segment. A gem based on this idea has been extracted to https://github.com/salsify/omniauth-multi-provider-saml.
require 'omniauth'
require 'omniauth-saml'
class MultiProviderSamlHandler
UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
attr_reader :path_prefix, :provider_name
def initialize(path_prefix: OmniAuth.config.path_prefix, provider_name: 'saml')
@path_prefix = path_prefix
# Better each() for use with coffeescript
# 1. Wraps child in jquery object
# 2. Sets child first argument, so that fat-binding can be used.
# 3. Sets @ as well, for normal binds
jQuery.fn.loop = (block) ->
for i in @
element = jQuery(i)
res = block.call element, element
break if res == false
@beneggett
beneggett / gist:4060792
Created November 12, 2012 17:45 — forked from anonymous/2.txt
Error CONNECTION REFUSED
def create_url
country = Country.where(:name => params[:country]).first
@wine = Wine.create(
:name => params[:name],
:country => BSON::ObjectId.from_string(country.id.to_s),
:region => params[:region],
:varietal => params[:varietal],
:producer => params[:producer],
:wine_type => params[:wine_type],
:year => params[:year],
def aviarycreate
@photo = Photo.new
@photo.user_id = current_user.id
@photo.remote_image_url = params[:url]
@photo.save
respond_to do |format|
format.json { render json: @photo }
end
end