Skip to content

Instantly share code, notes, and snippets.

@dreadjr
dreadjr / gist:dbd975676848f2d3ec49
Created November 5, 2015 21:03 — forked from jason-engage/gist:e072cc300fd789e8841e
Ionic Register Push Function Example with Payload and ionicPopup for Android and IOS
//Here is the curl commands I use to test - make sure you update the CAPSVARS. You can add an item ID Payload or not.
//For example if your app displays items, it can navigate to a specific item.
//If you want to add more state names, instead of only going to specific items:
//add another payload property called 'stateName'
//create a goState() function to accept a stateName as a parameter
//and modify the registerPush() to find the stateName property and pass into your goState().
//Android
curl -u YOURAPIKEY: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: APPID" https://push.ionic.io/api/v1/push -d '{"tokens":["ANDROIDTOKEN"],"notification":{"alert":"I come from planet Ion.", "android":{"title":"This is a title2", "payload":{"sound":"notification.mp3","itemId":"7TF00hJI78Y"}}}}'
@dreadjr
dreadjr / facebook_leads.md
Created January 29, 2016 23:33 — forked from tixastronauta/facebook_leads.md
Receiving Facebook Leads on a Webhook

Receiving Facebook Leads on a Webhook

1 - Create an App

Head over to developer.facebook.com and create an App

2 - Setup the webhook

On your server, create a facebook webhook that will handle facebook calls. Then create a "leadgen" webhook on you App: https://developers.facebook.com/docs/graph-api/webhooks/v2.5

@dreadjr
dreadjr / bytesToSize.js
Created February 8, 2016 18:00 — forked from lanqy/bytesToSize.js
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@dreadjr
dreadjr / ShortenNumbers.js
Created March 14, 2016 18:02 — forked from etaubman/ShortenNumbers.js
Shorten Numbers Using Javascript
function shortenNumber(n, d) {
if (n < 1) return "<1";
var k = n = Math.floor(n);
if (n < 1000) return (n.toString().split("."))[0];
if (d !== 0) d = d || 1;
function shorten(a, b, c) {
var d = a.toString().split(".");
if (!d[1] || b === 0) {
return d[0] + c
@dreadjr
dreadjr / aws-sns-example.js
Last active April 13, 2016 23:19 — forked from tmarshall/aws-sns-example.js
aws-sdk sns example, in Node.js
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: '{AWS_KEY}',
secretAccessKey: '{AWS_SECRET}',
region: '{SNS_REGION}'
});
var sns = new AWS.SNS();
@dreadjr
dreadjr / gist:18ae049ccdcd73550de23f6de5bcdecb
Created April 28, 2016 00:00 — forked from tschellenbach/gist:b0f1cf65647cb0acd0ef
GetStream.io aggregated notification feed example
# Instantiate a new client
import stream
client = stream.connect('key', 'secret')
# Assume the notification is aggregated on
# {% if verb.infinitive == 'like' %}{{ object }}{% else %}{{ id }}{% endif %}
notification_feed = client.feed('notification', '1')
# Add two likes, one comment and two follows
activities = [
@dreadjr
dreadjr / global.js
Created April 30, 2016 07:05 — forked from katowulf/global.js
Overriding error handling in AngularFire by extending and decorating $$error
// this will remove all error logging globally
angular.config(function($provide) {
$provide.decorator("$firebaseObject", function($delegate) {
$delegate.prototype.$$error = function(err) {
this.$destroy(err);
};
return $delegate;
});
$provide.decorator("$firebaseArray", function($delegate) {
@dreadjr
dreadjr / example.js
Last active June 8, 2016 05:50 — forked from colingourlay/example.js
Lodash / Underscore sort object keys. Like _.sortBy(), but on keys instead of values, returning an object, not an array. Defaults to alphanumeric sort.
var obj = {b: 3, c: 2, a: 1};
_.sortKeysBy(obj);
// {a: 1, b: 3, c: 2}
_.sortKeysBy(obj, function (value, key) {
return value;
});
// {a: 1, c: 2, b: 3}
@dreadjr
dreadjr / webpack.config.js
Created July 26, 2016 07:24 — forked from wonderbeyond/webpack.config.js
webpack config for our complex RequireJS code base
var path = require('path');
var webpack = require('webpack');
var ModuleReplace = webpack.NormalModuleReplacementPlugin;
module.exports = {
entry: {
'zjs/js/zyb_transfer_launch': 'zjs/js/zyb_transfer_launch.js',
},
output: {
@dreadjr
dreadjr / etl.md
Created October 4, 2016 00:14 — forked from dannycoates/etl.md
AWS Lambda for ETL

Experimenting with AWS Lambda for ETL

A lot of us are interested in doing more analysis with our service logs so I thought I'd share an experiment I'm doing with Sync. The main idea is to transform the raw logs into something that'll be nice to query and generate reports with in Redshift.

The Pipeline

Pipeline Diagram

Logs make their way into an S3 bucket (lets call it the 'raw' bucket) where we've got a lambda listening for new data. This lambda reads the raw heka protobuf gzipped data, does some transformation and writes a new file to a different S3 bucket (the 'processed' bucket) in a format that is redshift friendly (like json or csv). There's another lambda listening on the processed bucket that loads this data into Redshift.