Skip to content

Instantly share code, notes, and snippets.

View johndstein's full-sized avatar

John Stein johndstein

View GitHub Profile
@johndstein
johndstein / mssql-stream-insert.js
Last active June 15, 2021 20:16
Node.js writable stream that connects to db, drops and creates table, and then bulk loads rows into table
#!/usr/bin/env node
'use strict';
// Stream unlimited rows into a Sql Server table.
// WARNING!!! WE DROP and RE-CREATE the table. Then stream the data into it.
// Source stream must be an object stream. Object property names must match
// table column names. Since SQL Server isn't case sensitive, don't think case
@johndstein
johndstein / any-source-readable.js
Last active June 7, 2018 18:54
Custom Node.js readable stream that accepts data from any source
'use strict';
const Readable = require('stream').Readable;
// Easily turn anything into a readable stream.
// This is pretty much taken verbatim from the node documentation. Why re-invent
// the wheel?
// https://nodejs.org/api/stream.html#stream_readable_push_chunk_encoding
@johndstein
johndstein / mssql-stream-insert-example.js
Created October 21, 2016 16:51
Working example of Node.js readable and writable stream implementation
'use strict';
// This is a working example of a readable stream sending rows to insert into
// SQL Server.
const Readable = require('stream').Readable;
const mssql = require('mssql');
const MsSqlStreamInsert = require('../../lib/source/mssql-stream-insert');
const showProgress = require('../../lib/transform/show-progress')();
const options = require('../../.config');
@johndstein
johndstein / Batchable.java
Created September 23, 2016 13:47
salesforce Batchable
global with sharing class CertifiedFacilityWordPressSync implements Schedulable, Database.Batchable<sObject>, Database.AllowsCallouts {
class WordpressSyncJobException extends Exception {}
global static String scheduleIt(String jobName, String CRON_EXP) {
CRON_EXP = CRON_EXP != NULL ? CRON_EXP : '0 0 0/1 1/1 ? ';
jobName = jobName == null ? 'Certified Facility WordPress Sync' : jobName;
CertifiedFacilityWordPressSync cfwp = new CertifiedFacilityWordPressSync();
return System.schedule(jobName, CRON_EXP, cfwp);
}
@johndstein
johndstein / Batchable.java
Created September 23, 2016 13:47
salesforce Batchable
global with sharing class CertifiedFacilityWordPressSync implements Schedulable, Database.Batchable<sObject>, Database.AllowsCallouts {
class WordpressSyncJobException extends Exception {}
global static String scheduleIt(String jobName, String CRON_EXP) {
CRON_EXP = CRON_EXP != NULL ? CRON_EXP : '0 0 0/1 1/1 ? ';
jobName = jobName == null ? 'Certified Facility WordPress Sync' : jobName;
CertifiedFacilityWordPressSync cfwp = new CertifiedFacilityWordPressSync();
return System.schedule(jobName, CRON_EXP, cfwp);
}
public with sharing class DuesCalculator {
public DuesCalculator() {
}
public Decimal getAnnualDues(Id contactId) {
return 1;
}
@johndstein
johndstein / add_prod.java
Last active August 25, 2016 19:49
Add michbusiness products to memberships
String MEMBERSHIP_RECORD_TYPE = '01236000000nXvOAAU';
void addProducts(List<Opportunity> opps) {
List<OpportunityLineItem> olis = new List<OpportunityLineItem>();
Id oppId = null;
for (Opportunity o : opps) {
PricebookEntry pbe = getPricebookEntry('NEW_MEMBERSHIP');
if (o.Id == oppId) {
@johndstein
johndstein / gllock.java
Last active July 6, 2016 20:13
christar one time gl lock
public void lock() {
List<Donation_Designation__c> dds = getRowsToLock();
List<Opportunity> ops = getOppList(dds);
System.debug('Size: ' + dds.size());
for (Donation_Designation__c d : dds) {
d.GL_Lock_Date__c = Date.parse('3/29/2016');
}
for (Opportunity o : ops) {
o.GL_Lock_Date__c = Date.parse('3/29/2016');
}
@johndstein
johndstein / rea.sql
Created July 5, 2016 14:44
Raisers Edge Attributes
select *
from dbo.ConstituentAttributes as ca
inner join dbo.CONSTITUENT as con on ca.PARENTID = con.id
inner join dbo.attributetypes as at on ca.attributetypesid = at.attributetypesid
inner join dbo.TABLEENTRIES as te on te.CODETABLESID = at.CODETABLESID
inner join dbo.CODETABLES as ct on ct.CODETABLESID = at.CODETABLESID
where at.recordtype = 1
and at.TYPEOFDATA > 5
-- codetables will tell you the category, (Ex. Magazine) and tableentries will tell you a specific value, (Ex, Spring 05)
@johndstein
johndstein / mr.java
Last active June 7, 2016 13:09
Latest Good Simple Membership Renewal
/**
* Automatically creates a membership renewal opportunity so many days
* before the old membership expires.
*
* New membership starts on the expiration date of the old membership and is
* valid for specified number of months.
*
* We created the following opp custom fields specifically for this purpose.
*
* * Membership_Auto_Renew_Days_Prior__c