Skip to content

Instantly share code, notes, and snippets.

View dpickett's full-sized avatar

Dan Pickett dpickett

View GitHub Profile
View app_controllers_multtenant_behaviors.rb
module MultitenantBehaviors
protected
def current_company
if request.subdomain && request.subdomain != 'www'
# assumes a `subdomain` string field on the Company class / table
@current_company ||= Company.find_by(subdomain: request.subdomain)
else
nil
end
end
@dpickett
dpickett / fetch-in-rails-config.md
Created April 26, 2018 20:49
Fetch in Rails Config
View fetch-in-rails-config.md

Fetch in Rails Config

Once Rails is probably configured in our Rails application, we are not out of the jungle yet. We will also need to properly configure our applications such that our fetch requests communicate effectively with Rails. Let's briefly touch on these:

Rails Options

Rails has built in securities and config that make it very selective about the requests that are allowed to come in. We'll need to edit our controller configuration to allow fetch requests and their json formats so that we can respond accordingly.

View weather.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Weather</title>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
View officiant.rb
require 'date'
class Officiant
def authorized?
is_minister_of_the_gospel? || willing_to_get_ordained_online?
end
def available?(date)
!not_really_interested && !busy?(date) && !generally_too_busy
end
View main.js
let React = require('react')
let ReactDOM = require('react-dom')
var Hello = React.createClass({
getInitialState: function(){
return {
}
},
updateName: function(event){
this.setState({
View simple-widget.js
var Hello = React.createClass({
getInitialState: function(){
return {
}
},
updateName: function(event){
this.setState({
name: event.target.value
})
},
View webpack.config.js
require('babel-loader')
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: {
path: './src/main.js'
},
output: {
path: './build',
View long_string.rb
puts "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " +
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." +
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris"
View gist:e1b14fd602d50f6e21ff
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Uncomment the following line to use case-sensitive completion.
@dpickett
dpickett / player_pseudo.js
Last active August 29, 2015 14:03
players
View player_pseudo.js
function KeyHandler(){
//handy underscoreJS function
_.bindAll(this, 'handleUpKey', 'handleKey');
this.handleUp = function(e){
//we can use jQuery to trigger events on plain ol' JavaScript objects
$(this).trigger('up');
}
this.handleKey = function(e){