Skip to content

Instantly share code, notes, and snippets.

@lambtron
lambtron / jsontocsv.js
Last active August 29, 2015 14:11
Read from json input file and output to another file as csv.
/**
* Module dependencies.
*/
var readline = require('readline');
var stream = require('stream');
var fs = require('fs');
/**
@lambtron
lambtron / utm_params_last_touch.html
Last active October 12, 2015 07:40
Tracking last_touch with UTM params
<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 / textme.html
Last active December 10, 2015 22:09
This is the home page of the TextMe! application. This describes how the user would put in his/her phone number and generate a link that would be dragged to the toolbar to act as a bookmarklet.
<section class="form">
<input type="text" placeholder="xxx-xxx-xxxx">
<button type="submit">Make my bookmarklet!</button>
</section>
<section id="bookmarklet-container">
<span><p>Your link will be generated below and drag it to your toolbar!</p></span>
<div id="bookmarklet">
</div>
</section>
@lambtron
lambtron / twiliocontroller.rb
Created January 10, 2013 08:39
Ruby server code that allows for CORS and sends an SMS via Twilio.
require 'rubygems'
require 'twilio-ruby'
require 'net/http'
require 'uri'
require 'json'
class TwilioController < ApplicationController
TWILIO_ACCOUNT_SID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
TWILIO_ACCOUNT_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
SENDER_NUMBER = '+xxxxxxxxxx'
{
"name": "the-daily-koala",
"description": "automated lulz generator",
"version": "0.0.1",
"private": true,
"engines": {
"node": "0.8.x",
"npm": "1.1.x"
},
"dependencies": {
// 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'));
@lambtron
lambtron / inbox_controller.rb
Last active December 19, 2015 04:38
Twilio Click to call in the inbox controller
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 / clicktocallcallscreen.xml.builder
Created July 1, 2013 03:56
Click to call, call screen 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 / clicktocall.xml.builder
Created July 1, 2013 03:57
Click To Call xml builder
xml.instruct!
xml.Response do
xml.Dial @calling_to, :callerId => @caller_id
end
@lambtron
lambtron / sorter.js
Created October 20, 2015 17:27
Custom sort method for metalsmith-collections plugin in Segment's technical documentation.
/**
* 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