Skip to content

Instantly share code, notes, and snippets.

View ryanbrainard's full-sized avatar

Ryan Brainard ryanbrainard

View GitHub Profile
function processSignedRequest($signedRequest, $secret) {
$sep = strpos($signedRequest, '.');
$encodedSig = substr($signedRequest, 0, $sep);
$encodedEnv = substr($signedRequest, $sep + 1);
$calcedSig = base64_encode(hash_hmac("sha256", $encodedEnv, $secret, true));
if ($calcedSig != $encodedSig) {
throw new Exception("Signed request authentication failed");
}

Java configuration with Maven

The New Relic Java agent is available as a Maven dependency that can be automatically downloaded and installed during your project's build. This has the advantage of not having to check the agent into your project's source control and makes it easier to change versions in the future.

Add New Relic to your POM

  1. Add newrelic-java as a dependency. Check Maven Central for the latest version:

     <dependency>
    

com.newrelic.agent.java

<?xml version="1.0" encoding="UTF-8"?>
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
<recordTypeVisibilities>
<default>true</default>
<personAccountDefault>true</personAccountDefault>
<recordType>MyObject__c.A</recordType>
<visible>true</visible>
</recordTypeVisibilities>
<recordTypeVisibilities>
<default>false</default>
@ryanbrainard
ryanbrainard / 0 Visualforce Page
Last active December 26, 2015 11:59
Force.com Code Samples
<apex:page standardController="Invoice__c" sidebar="false" showHeader="false" >
{!Invoice__c.name}<br/>
{!Invoice__c.Status__c}
<ul>
<apex:repeat value="{!Invoice__c.Line_Items__r}" var="item">
<li>{!item.name}</li>
</apex:repeat>
</ul>
</apex:page>
@ryanbrainard
ryanbrainard / dataclip-column
Last active January 4, 2016 18:59
Script for extracting a single column from a Heroku Dataclip. Designed for piping into commands like xargs. Requires jq be installed.
#!/usr/bin/env bash
error() {
printf "$1\n" >&2
exit 1
}
[[ $# -eq 0 ]] && error "Usage: `basename $0` hash column [row(s)]"
hash=${1?'Must provide Dataclip hash'}
@ryanbrainard
ryanbrainard / gist:9765354
Last active August 29, 2015 13:57
Example of using `_HttpMethod=PATCH` query param with clients that do not support `PATCH`.
> POST /services/data/v29.0/sobjects/Component__c/a1IV0000000MN90MAG?_HttpMethod=PATCH HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
> Host: cs12.salesforce.com
> Accept: */*
> X-PrettyPrint: 1
> Authorization: Bearer REDACTED
> Content-Type: application/json
> Content-Length: 20
>
* upload completely sent off: 20 out of 20 bytes
@ryanbrainard
ryanbrainard / cache
Last active April 23, 2020 22:47
Bash Cache
#!/bin/sh
# forked from http://stackoverflow.com/a/11901300/129492
if [ $# == 0 ] || [ $1 == '-h' ] || [ $1 == '--help' ]; then
echo 'cache - cache the output of a command'
echo
echo 'Usage: cache [options] <command>'
echo
echo 'Options:'
echo ' -r, --reset [command]'
@ryanbrainard
ryanbrainard / PromiseStateContainer.jsx
Last active May 19, 2022 13:17
Example PromiseStateContainer
import React, { Component, PropTypes } from 'react'
import { connect, PromiseState } from 'react-refetch'
import LoadingAnimation from './LoadingAnimation'
import ErrorBox from './ErrorBox'
class PromiseStateContainer extends Component {
static propTypes = {
ps: PropTypes.instanceOf(PromiseState).isRequired,
onPending: PropTypes.func,
onNoResults: PropTypes.func,
@ryanbrainard
ryanbrainard / Profile.jsx
Created December 20, 2015 02:01
PromiseStateContainer Usage Example
import React, { Component, PropTypes } from 'react'
import { connect, PromiseState } from 'react-refetch'
import PromiseStateContainer from './PromiseStateContainer'
export default class Profile extends Component {
render() {
const { userFetch, likesFetch } = this.props
return (
<PromiseStateContainer
@ryanbrainard
ryanbrainard / file1.txt
Created January 12, 2017 06:31
the description for this gist
String file contents