Skip to content

Instantly share code, notes, and snippets.

Avatar

Andy Jiang lambtron

View GitHub Profile
@lambtron
lambtron / la_vs_sf_yelp_scraper.py
Created Nov 2, 2018
LA vs. SF: which city has more diverse cuisine?
View la_vs_sf_yelp_scraper.py
#
# Module dependencies.
#
import os
import csv
import itertools
import collections
from yelpapi import YelpAPI
@lambtron
lambtron / sorter.js
Created Oct 20, 2015
Custom sort method for metalsmith-collections plugin in Segment's technical documentation.
View sorter.js
/**
* Generate a custom sort method for given starting `order`. After the given
* order, it will ignore casing and put periods last. So for example a call of:
*
* sorter('Overview');
*
* That is passed:
*
* - Analytics.js
@lambtron
lambtron / utm_params_last_touch.html
Last active Oct 12, 2015
Tracking last_touch with UTM params
View utm_params_last_touch.html
<script type="text/javascript">
function getQueryParam(url, param) {
param = param.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + param + "=([^&#]*)",
regex = new RegExp(regexS),
results = regex.exec(url);
if (results === null || (results && typeof(results[1]) !== 'string' && results[1].length)) {
return '';
} else {
return decodeURIComponent(results[1]).replace(/\+/g, ' ');
@lambtron
lambtron / shopify.md
Last active Dec 22, 2020
segment event tracking for shopify
View shopify.md
title sidebar
Segment Event Tracking for Shopify
Shopify

Segment makes it simple for Shopify merchants to integrate analytics, email marketing, advertising and optimization tools. Rather than installing all your tools individually, you just install Segment once. We collect your data, translate it, and route it to any tool you want to use with the flick of a switch. Using Segment as the single platform to manage and install your third-party services will save you time and money.

The guide below explains how to install Segment in your Shopify store. All you need to get up and running is copy and paste a few snippets of code into your theme editor. (You don't have to edit the code or be versed in JavaScript.) The following guide will show you how, step by step.


@lambtron
lambtron / jsontocsv.js
Last active Aug 29, 2015
Read from json input file and output to another file as csv.
View jsontocsv.js
/**
* Module dependencies.
*/
var readline = require('readline');
var stream = require('stream');
var fs = require('fs');
/**
@lambtron
lambtron / clicktocall.xml.builder
Created Jul 1, 2013
Click To Call xml builder
View clicktocall.xml.builder
xml.instruct!
xml.Response do
xml.Dial @calling_to, :callerId => @caller_id
end
@lambtron
lambtron / clicktocallcallscreen.xml.builder
Created Jul 1, 2013
Click to call, call screen xml builder
View clicktocallcallscreen.xml.builder
xml.instruct!
xml.Response do
xml.Gather(:action => @post_to, :numDigits => 1, :timeout => '10') do
xml.Say "Press a key to accept", :voice => :woman
end
xml.Say "You didn't press anything. Goodbye.", :voice => :woman
xml.Hangup
end
@lambtron
lambtron / inbox_controller.rb
Last active Dec 19, 2015
Twilio Click to call in the inbox controller
View inbox_controller.rb
require 'twilio-ruby'
class InboxController < ApplicationController
BASE_URL = 'http://www.andyjiang.com/'
# /click-to-call-request
def click_to_call(calling_to)
# debugging purposes.
twilio_number = '4154444444'
calling_to = digits_only(calling_to)
@lambtron
lambtron / inbox_controller.rb
Last active Jun 21, 2019
Parsing inbound email from Mandrill for the SF apartment hunt.
View inbox_controller.rb
require 'mechanize'
class InboxController < ApplicationController
include Mandrill::Rails::WebHookProcessor
# For the apartment hunt.
def parse_inbound_sf_apartment_email
# Mandrill needs an ok in order to proceed to POST Mandrill events to this endpoint.
if request.head?
head :ok
View server.js
// Importing modules.
var express = require('express');
var fs = require('fs');
var image = require('./image');
// Configuration.
var app = express();
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use('/resources', express.static(__dirname + '/resources'));