Skip to content

Instantly share code, notes, and snippets.

View rob-mcgrail's full-sized avatar
🐟
codin

Rob McGrail rob-mcgrail

🐟
codin
  • Haunt
  • New Zealand
  • 21:08 (UTC +12:00)
View GitHub Profile
@rob-mcgrail
rob-mcgrail / AppPushwooshNotifiable.js
Last active October 5, 2017 20:56
Pushwoosh Redux RN integration example.
import React from 'react';
import { Provider } from 'react-redux';
import { Router, AndroidBackButton } from 'react-router-native';
import { StyleProvider } from '@shoutem/theme';
/* Local components */
import StoredSession from 'src/components/connected/StoredSession';
import NotifiableDevice from 'src/components/connected/NotifiableDevice';
import Routes from 'src/routes';
import axios from 'axios';
import config from 'src/config';
export default axios.create({
baseURL: config.apiBaseUrl,
timeout: 3000,
headers: {
'content-type': 'application/json'
}
});
import { connect } from 'react-redux';
import HOCPrivateRoute from 'src/components/utility/PrivateRoute';
function mapStateToProps(state) {
return {
authenticated: state.auth.authenticated,
redirectTo: '/welcome'
};
}
@rob-mcgrail
rob-mcgrail / Loading.js
Last active September 6, 2017 02:33
Wrap children in a loader that fetches authentication data from the phone's storage and bootup.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
const Loading = (Wrapped, action) => class extends Component {
static propTypes = {
action: PropTypes.func
}
static defaultProps = {
action: false
import { Component } from 'react';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router-native';
const HistoryListener = class extends Component {
static propTypes = {
history: PropTypes.object.isRequired,
callback: PropTypes.func.isRequired,
delay: PropTypes.number
}
module Users
class Profile < ApplicationRecord
include ::Calculator::Profile # Let anything with this act as a profile?
end
end
module Trends
class Profile < ApplicationRecord
include ::Calculator::Profile # And if we need ad-hoc profiles,
# make classes for them
module EntityChangeCallbacks
extend ActiveSupport::Concern
# This concern allows us to treat lists of entity
# attributes as a unit, with their own create and update
# callbacks.
#
#
# create_change_callback name: :profile,
# attributes: [
@rob-mcgrail
rob-mcgrail / sitemap.rb
Created April 18, 2017 22:23
config/sitemap.rb
# Set the host name for URL creation
protocol = ENV['PROTOCOL'] || 'http'
SitemapGenerator::Sitemap.default_host = "#{protocol}://#{ENV['HOST']}"
SitemapGenerator::Sitemap.compress = false
SitemapGenerator::Sitemap.create do
add('/topics')
add('/concepts')
@rob-mcgrail
rob-mcgrail / patch_for_jsonapi_authorization_relations.rb
Created November 8, 2016 22:36
authorize via relate? with a reference to the related class.
module JSONAPI
module Authorization
class DefaultPunditAuthorizer
def create_resource(source_class, related_records)
::Pundit.authorize(user, source_class, 'create?')
related_records.each do |record|
user.define_singleton_method(:source_class) do
source_class
end
@rob-mcgrail
rob-mcgrail / airbrake.rb
Last active January 14, 2016 02:02
Airbrake config
# https://github.com/airbrake/airbrake-ruby#configuration
Airbrake.configure do |c|
# You must set both project_id & project_key. To find your project_id and
# project_key navigate to your project's General Settings and copy the values
# from the right sidebar.
# https://github.com/airbrake/airbrake-ruby#project_id--project_key
c.project_id = 'xxxx'
c.project_key = 'xxxxxxxxxxx'
c.root_directory = Rails.root
c.logger = Rails.logger