Skip to content

Instantly share code, notes, and snippets.

@BradRuderman
BradRuderman / fix_string_type.js
Last active May 2, 2016 21:31
query to fix string types to float/ints
db.users.find({"AttorneyLeadScore":{$exists:true}}).forEach(function(doc){
if (doc.AttorneyLeadScore && doc.AttorneyLeadScore.length > 0){
var as = doc.AttorneyLeadScore;
if (typeof(as[0]) == 'string'){
for (var i = 0; i < as.length; i++){
as[i] = parseInt(as[i]);
}
print("Updating " + doc._id + ' to ' + as.toString());
//db.users.update({"_id":doc._id},{$set : { 'AttorneyLeadScore' : as}});
}
@BradRuderman
BradRuderman / pymaketo.py
Created March 8, 2016 18:54
Wrapper Class for Marketo API
import requests, datetime, time
class PyMarketo(object):
def __init__(self, client_id, client_secret, instance_id):
self.client_id = client_id
self.client_secret = client_secret
self.instance_id = instance_id
self.url = "https://{0}.mktorest.com".format(self.instance_id)
self.get_token()
As a business user I want my KPI chart to be updated in realtime. Currently our KPI summary look is built using a PDT.
The reason is because we want to show the count of different events around the same time dimension.
For example if I want to show the number of orders completed and number of orders shipped in the same look.
| order_id | ordered_at | shipped_at|
1 | 2016-01-01 | 2016-01-02
2 | 2016-01-01 | 2016-01-01
Filter = 2016-01-01
Orders Complete | Orders Shipped
@BradRuderman
BradRuderman / gist:458e98d6a3b21451d006
Created October 19, 2015 22:31
postgres jsonb unpack
SELECT cookies
FROM user_tracking;
"{""ut"": ""53c634eaf8c00000"", ""_ga"": ""GA1.2.940800967.1439230570"", ""_gat"": ""1"", ""kvcd"": ""1445290560648"", ""km_ai"": {""$oid"": ""55c919683dab086217cc148a""}, ""km_lv"": ""x"", ""km_ni"": {""$oid"": ""55c919683dab086217cc148a""}, ""km_uq"": """", ""km_vs"": ""1"", ""__unam"": ""efb39fc-14f1e3fe5c5-562d6fa2-41"", ""optimizelyBuckets"": ""{\""2945870022\"":\""2917090094\"",\""3266580013\"":\""3267360019\"",\""3526560225\"":\""3549300107\""}"", ""optimizelySegments"": ""{\""286422970\"":\""false\"",\""286623248\"":\""gc\"",\""286939202\"":\""referral\"",\""1668900787\"":\""gc\"",\""1675520668\"":\""direct\"",\""1676290438\"":\""false\"",\""2150870732\"":\""gc\"",\""2154301211\"":\""direct\"",\""2170820224\"":\""false\""}"", ""optimizelyEndUserId"": ""oeu1439230569544r0.09696912136860192""}"
SELECT cookies->'optimizelyBuckets'
FROM user_tracking;
"""{\""2945870022\"":\""2917090094\"",\""3266580013\"":\""3267360019\"",\""3526560225\"":\""3549300107\""}"""
@BradRuderman
BradRuderman / test.js
Created July 23, 2015 05:18
queue test
var timeoutHandle;
var i=0;
function worker(){
function onDelete(err){
if(err){
console.log(err);
}
}
@BradRuderman
BradRuderman / iron_memory_output.txt
Created July 22, 2015 20:33
Iron Worker Memory Output
27836
28376
31220
32316
32928
34088
35168
36288
38592
40704
@BradRuderman
BradRuderman / photos_app_duplicates.py
Last active August 29, 2015 14:19
Photo Apps Duplicates
from os.path import expanduser
import os
import hashlib
#Replace the following line with the location of your photo's library. The default location is the home
#directory.
PATH_TO_PHOTOS_LIBRARY = expanduser("~") + '/Pictures/Photos Library.photoslibrary'
hashes = []
for subdir, dirs, files in os.walk(PATH_TO_PHOTOS_LIBRARY + '/Masters'):
@BradRuderman
BradRuderman / LeadConversion
Created September 29, 2014 07:00
Lead Conversion Rest
@RestResource(urlMapping='/ConvertLead/')
global with sharing class RestLeadConversion {
public static Boolean THROW_EXCEPTION = false;
public class UnhandledException extends Exception {}
public static void generateExceptionForTesting() {
if (Test.isRunningTest() && THROW_EXCEPTION) {
throw new UnhandledException('Exception for testing');
}
}
file a.js
------------
var users = {};
var tests = {};
MakeUsesrHttpCall(function(err,res){
users = res;
});
@BradRuderman
BradRuderman / redisWorker
Created September 10, 2014 18:40
Redis Queue Issue
var config = require('../../config/config.js'),
RedisQueue = require('simple-redis-safe-work-queue');
function processEvent(e, cb) {
console.log("Processing Event");
cb();
}
var options = {
host: config['redisConnection'],