Skip to content

Instantly share code, notes, and snippets.

View beneggett's full-sized avatar

Ben Eggett beneggett

View GitHub Profile
# ...
<%= domain_stylesheet_link_tag "application", media: "all" %>
<%= domain_javascript_include_tag "application" %>
#...
require 'httparty'
class Weather
attr_accessor :city
def initialize(city)
@city = CGI.escape(city)
end
@beneggett
beneggett / gist:a93171c489df122a3419
Created October 2, 2014 02:14
GIt sync my projects
DIRECTORY_TO_SYNC=~/Sites/my-repo-path/; for REPO in `ls $DIRECTORY_TO_SYNC`; do (cd "$DIRECTORY_TO_SYNC/$REPO"; pwd; git pull); done; unset DIRECTORY_TO_SYNC;
# zshell alias:
pullrepos() {DIRECTORY_TO_SYNC=~/Sites/my-repo-path/; for REPO in `ls $DIRECTORY_TO_SYNC`; do (cd "$DIRECTORY_TO_SYNC/$REPO"; pwd; git pull); done; unset DIRECTORY_TO_SYNC;}
@beneggett
beneggett / pair
Last active August 29, 2015 14:09
pair
#!/usr/bin/env bash
# Usage: pair [<github-user>] [-t <tmux-session>]
#
# Copy the command to clipboard which grants another person access to the tmux
# session on your machine. The resulting command is in format:
#
# ssh -t <USER>@<HOST> 'tmux attach -t <SESSION>'
#
# When given a GitHub username, it will adopt SSH keys from their GitHub
# account and add them to your `~/.ssh/authorized_keys`.
@beneggett
beneggett / create_oauth_tables.rb
Last active August 28, 2023 18:03
Postgresql multiple schemas in rails
class DbSetup < ActiveRecord::Migration
def up
create_schema :oauth
create_table "oauth.oauth_applications" do |t|
t.string :name, null: false
t.string :uid, null: false
t.string :secret, null: false
t.text :redirect_uri, null: false
t.integer :owner_id, null: false
@beneggett
beneggett / generate.sh
Created December 1, 2014 21:27
ssl-cert-request
# Create a private key
openssl genrsa -des3 -out server.pass.key 2048
# Strip password from private key
openssl rsa -in server.pass.key -out server.key
# Generate a CSR
openssl req -nodes -new -key server.key -out server.csr
# For NGINX, request a single PEM certificate, otherwise you'll get a SSL authority cert & site cert.
# admin/seo/_seo_form.html.erb
<div class='full-inputs'>
<%= simple_form_for seo, remote: true, url: admin_update_seo_path(seo) do |f| %>
<%= f.input :content, required: true, as: :text, input_html: {rows: 2, maxlength: "#{ seo.name == 'title' ? '70' : '155' }"}, label: seo.name.try(:humanize), hint: "<span class='character-count green'> </span> #{seo.name.try(:humanize)} should be no longer than #{ seo.name == 'title' ? '70' : '155' } characters" %>
<div class='text-center'>
<button class='btn btn-primary'>Update</button>
<a href="#<%= page %>" class='cancel-seo btn btn-warning' data-attribute="<%=f.object.id %>"> Cancel</a>
<% end %>
# 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:ad024efc9a4c9ec3b89cde6165d94c0b
Created April 11, 2016 22:50
Get octal permissions command line
stat -c "%a %n" *
@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