Skip to content

Instantly share code, notes, and snippets.

View kevinohara80's full-sized avatar

Kevin O'Hara kevinohara80

View GitHub Profile
@kevinohara80
kevinohara80 / IdStringIssueTrigger.trigger
Last active December 19, 2015 00:38
Another Spring '13 String/Id bug having to do with the use of instanceof
trigger IdStringIssueTrigger on Lead (after insert) {
String leadId = Trigger.new[0].Id;
SObject so = [SELECT Id, FirstName, LastName FROM Lead WHERE Id = :leadId];
if(so.get('FirstName') instanceof Id) {
Trigger.new[0].FirstName.addError('Apex thinks this is an ID!!!'); // errors always
}
}
@kevinohara80
kevinohara80 / ScheduledJob.cls
Last active December 19, 2015 00:19
Repro code for Apex Summer '13 String/Id issue with System.abortJob(String);
global class ScheduledJob implements Schedulable {
global void execute(SchedulableContext sc) {
System.debug('Executing');
}
global static void schedule() {
ScheduledJob job = new ScheduledJob();
System.schedule('Test Job', '0 0 13 * * ?', job);
}
trigger OpportunityTrigger on Opportunity (before insert, before update, before delete,
after insert, after update, after delete, after undelete) {
(new OpportunityTriggerHandler()).run();
}
// return the value of $ back to it's original owner
jQuery.noConflict();
(function($) {
// code
}(jQuery));
@kevinohara80
kevinohara80 / CampaignMemberTouch.cls
Last active December 16, 2015 17:09
Schedulable batch trigger invoke class
global class CampaignMemberTouch implements Schedulable{
global void execute(SchedulableContext SC) {
// kick off the batch with a size of 2 for the batch size
InvokeTriggerBatch.invoke('SELECT Id FROM CampaignMember', 5);
}
}
@kevinohara80
kevinohara80 / signed-request.js
Last active December 15, 2015 19:19
Example canvas signed request middleware for express.js
var crypto = require('crypto');
// canvas signed request midddleware for express
module.exports = function(options) {
if(!options) options = {};
function verify(signature, context) {
if(!options.consumerSecret) return false;
var hmac = crypto.createHmac('sha256', options.consumerSecret);
@kevinohara80
kevinohara80 / Gruntfile.js
Last active December 14, 2015 04:39
Gruntifle from my demo video for static resource deployment
module.exports = function(grunt) {
// project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
options: {
globals: {
jQuery: true,
console: true,
@kevinohara80
kevinohara80 / package.json
Last active December 11, 2015 09:49
Poll my home server so I know when the power is restored at my house. Alert me via text message. Written in node.js.
{
"name": "pollhouse",
"version": "0.0.0",
"description": "Poll my house, let me know when power is on",
"main": "poll.js",
"dependencies": {
"request": "~2.12.0",
"optimist": "~0.3.5",
"mailer": "~0.6.7"
}
@kevinohara80
kevinohara80 / .bash_profile
Last active December 11, 2015 05:19
Here is my command prompt from my .bash_profile. The command prompt detects whether it's in a git project or not and if it is, it indicates the current branch and whether there are un-staged changes pending.
# RETURN ASTERISK WHEN CHANGES ARE PRESENT BUT UNSTAGED
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
# GET THE CURRENT GIT BRANCH
function parse_git_branch() {
if [ -d "./.git" ]; then
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
fi
@kevinohara80
kevinohara80 / mw.js
Created December 12, 2012 18:13
express.js middleware function for checking that the nforce oauth data exists in the user's session.
app.use(function(req, res, next) {
if(!req.session.oauth) res.redirect('/authorize');
else next();
});