Skip to content

Instantly share code, notes, and snippets.

@joshbirk
joshbirk / samplerest.js
Created February 3, 2012 19:57
Sample of using passport w/ mult strategies
var fs = require("fs")
var ssl_options = {
key: fs.readFileSync('privatekey.pem'),
cert: fs.readFileSync('certificate.pem')
};
var port = process.env.PORT || 3000;
var express = require('express');
var ejs = require('ejs');
var passport = require('passport')
@joshbirk
joshbirk / checkemail.py
Created January 17, 2012 16:23
Python Script to check GMail account
#!/usr/bin/env python
def gmail_checker(username,password):
import imaplib,re
i=imaplib.IMAP4_SSL('imap.gmail.com')
try:
i.login(username,password)
x,y=i.status('INBOX','(MESSAGES UNSEEN)')
messages=int(re.search('MESSAGES\s+(\d+)',y[0]).group(1))
unseen=int(re.search('UNSEEN\s+(\d+)',y[0]).group(1))
return (messages,unseen)
@joshbirk
joshbirk / 1_WarehouseUtil.cls
Last active October 16, 2021 12:52
Utility Apex Class
global with sharing class WarehouseUtil implements Database.Batchable<sObject>, Schedulable {
@joshbirk
joshbirk / PieChartComponent.component
Created December 13, 2012 19:09
Advanced Visualforce Examples
<apex:component controller="WarehouseChartController">
<apex:attribute name="invoiceID" type="ID" description="The ID of the Invoice holding the Line Items" assignTo="{!invoiceID}"/>
<apex:chart data="{!data}" height="400" width="500" background="#F5F5F5">
<apex:legend position="left"/>
<apex:pieSeries labelField="name" dataField="data" donut="10">
<apex:chartLabel display="middle" orientation="vertical" font="bold 18px Helvetica"/>
</apex:pieSeries>
</apex:chart>
</apex:component>
@joshbirk
joshbirk / SpeedTest Apex Controller
Last active March 29, 2019 20:04
Lightning Chart Component w/ D3.js
public with sharing class SpeedTestController {
@AuraEnabled
public static List< SpeedTest__c > getData() {
List<SpeedTest__c> speeds = [SELECT ID, TimeString__c,Download__c,Upload__c from SpeedTest__c LIMIT 1000];
return speeds;
}
}
@joshbirk
joshbirk / 1: Create a new REST Endpoint
Created April 7, 2014 19:03
ELEVATE Extra Credit: Custom REST Responses
/*
In the Programmers workbook there is a tutorial on creating a basic REST endpoint using Apex. A common scenario with these
endpoints is needing to enhance the message that gets sent down to client. You can do this easily within Apex by defining
a custom class to use as a response, which will be converted to JSON by the platform.
To complete this extra credit:
1. Create a class from the code below
2. Update the POST and DELETE endpoints to use the RESTMessage class
3. Test the new endpoint with unit test in the next class
*/
@joshbirk
joshbirk / monkeytrigger.cls
Created January 21, 2013 18:17
Simple Chatter Trigger Example
trigger MonkeyChatter on FeedItem (after insert) {
//Get the key prefix for the Opportunity object via a describe call.
String keyPrefix = Monkey__c.sObjectType.getDescribe().getKeyPrefix();
List<Id> relatedIds = new List<Id>();
for(FeedItem f : Trigger.new) {
if(String.valueOf(f.parentId).startsWith(keyPrefix)) { //is a Monkey
if(f.body.contains('#givebanana')) {
relatedIds.add(f.parentId);
}
var sfStrategy = new ForceDotComStrategy({
clientID: CF_CLIENT_ID,
clientSecret: CF_CLIENT_SECRET,
callbackURL: CF_CALLBACK_URL,
authorizationURL: SF_AUTHORIZE_URL,
tokenURL: SF_TOKEN_URL
//the current sample lists the first param as "Token", but it's really an OAuth object Look at the params field on it.
}, function(oauth, refreshToken, profile, done) {
// asynchronous verification, for effect...
@joshbirk
joshbirk / pagehitscontroller.java
Created November 5, 2012 23:24
Apex Controller for CSV information
global class PageHitsController implements Messaging.InboundEmailHandler {
public PageHitsController() {
}
public Document document {
get {
if (document == null)
document = new Document();
@joshbirk
joshbirk / rsshandler.java
Created October 30, 2012 19:54
RSS Handler
global class RSSHandler implements Schedulable {
global RSSHandler() {
}
global void execute(SchedulableContext c) {
updateDeveloperBlog();
}