Skip to content

Instantly share code, notes, and snippets.

View chadwilken's full-sized avatar

Chad Wilken chadwilken

View GitHub Profile
@chadwilken
chadwilken / async_reindex_status.rb
Created June 23, 2022 14:56
Searchkick Async Workflow
module Searchkick
class AsyncReindexStatus
include Redis::Objects
def id
'searchkick-async-reindex-status'
end
list :currently_reindexing
end
@chadwilken
chadwilken / Document.jsx
Created March 2, 2020 18:20
React PDF w/ UGC
import React, { useMemo } from 'react';
import {
Document as PDFDocument,
StyleSheet,
Page,
Font,
} from '@react-pdf/renderer';
import dig from 'lodash.get';
import PageFooter from './PageFooter';
import CoverPage from './CoverPage';
@chadwilken
chadwilken / client.rb
Created February 4, 2020 16:11
CompanyCam OAuth 2 Flow
require 'oauth2'
client_id = 'your_client_id'
client_secret = 'your_client_secret'
redirect_uri = 'https://yoursite.com/oauth/authorize'
site = 'https://app.companycam.com'
client = OAuth2::Client.new(client_id, client_secret, site: site)
auth_url = client.auth_code.authorize_url(redirect_uri: redirect_uri, scope: 'read write destroy')
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => '', // Your client ID
'clientSecret' => '', // Your secret key
'redirectUri' => 'https://lonestarhazmatapp.com/wp-json/moserver/authorize', // This is where we redirect you/the user after they say it is okay for you to access CompanyCam on their behalf
'urlAuthorize' => 'https://app.companycam.com/oauth/authorize',
'urlAccessToken' => 'https://app.companycam.com/oauth/token'
]);
// If we don't have an authorization code then get one
// This would be in the Wordpress Admin UI, hook it up to a button or something
@chadwilken
chadwilken / base_controller.rb
Created February 1, 2020 19:44
Doorkeeper with Devise
class BaseController < ApplicationController
before_action :doorkeeper_authorize!, except: [:index, :show, :create, :update, :destroy] # Anything not caught below
before_action :authorize_read_actions!, only: [:index, :show]
before_action :authorize_write_actions!, only: [:create, :update]
before_action :authorize_destroy_actions!, only: [:destroy]
def current_user
unless defined?(@current_user)
if doorkeeper_token.present? && !doorkeeper_token.revoked?
@current_user ||= User.find_by(id: doorkeeper_token.resource_owner_id)
@chadwilken
chadwilken / client.rb
Created December 11, 2018 16:06
OAuth 2 Flow
client = OAuth2::Client.new(ENV['COMPANYCAM_UID'], ENV['COMPANYCAM_SECRET'], site: 'https://app.companycam.com')
# Get a auth URL to redirect user to
client.auth_code.authorize_url(redirect_uri: 'https://yoursite.com/oauth/companycam/callback')
# The user will accept of deny and then be redirected to the URL above
# the URL will have a parameter `code` if the user accepted.
# You will take the code and POST back to exchange for an access_token and refresh_token
client.auth_code.get_token(params[:code], redirect_uri: 'https://yoursite.com/oauth/companycam/callback')
@chadwilken
chadwilken / puma.service
Created August 23, 2018 20:38
Puma Systemd service
[Unit]
Description=Puma HTTP Server for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
After=network.target
Requires=puma.socket
[Service]
Type=simple
User=<%= fetch(:deploy_user) %>
Environment=RAILS_ENV=<%= fetch(:rails_env) %>
@chadwilken
chadwilken / collection.md
Last active July 9, 2018 15:20
Photos To Web Payload

Photo Collection

Attribute Type Description
version int The version of the photo collection, will increase as modifications are made
collectionUUID string A unique identifier for the collection, it will remain the same with subsequent versions
title string The title of the collection
subtitle string The subtitle of the collection
description string The long description explaining the project
categories Array A list of categories the user applied to the collection
// project will be https://docs.companycam.com/#the-project-object
const project = await fetch ('https://api.companycam.com/v2/projects', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer {access_token},
'X-CompanyCam-User': '{user_email}',
'X-CompanyCam-Secret': '{application_secret}'
},
@chadwilken
chadwilken / CreateProject.cs
Last active April 19, 2018 19:49
CompanyCam .NET Examples
// Set secret key for your application globally
CompanyCamConfiguration.SetSecretKey("YourSecretKey");
var requestOptions = new CompanyCamRequestOptions
{
ApiKey = "CompanyApiKey",
UserEmailAddress = "UserPerformingAction"
};
var projectService = new ProjectService(requestOptions);
var project = projectService.Create(new Project