Skip to content

Instantly share code, notes, and snippets.

@danromero
danromero / Gmail-Inbox-to-Spreadsheet
Created November 6, 2013 18:27
Simple Gmail inbox to spreadsheet script. Useful for running pivots on "Contact Us"-type emails (e.g. hi@yourdomain.com).
function processInbox() {
// get all threads in inbox
var threads = GmailApp.getInboxThreads();
for (var i = 0; i < threads.length; i++) {
// get current active Google Docs spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();
// get subject, to, from and date of 1st message in thread
sheet.appendRow([threads[i].getMessages()[0].getSubject(), threads[i].getMessages()[0].getTo(), threads[i].getMessages()[0].getFrom(), threads[i].getMessages()[0].getDate()]);
Utilities.sleep(1000);
}
@danromero
danromero / Heroku-Postgres-to-local-Postgres-to-pandas
Last active December 27, 2015 15:39
Commands to sanitize and import a Heroku Postgres dump into Postgres.app on a Mac
pg_restore dumpfile >plaintext.sql
iconv -c -f UTF-8 -t UTF-8 <plaintext.sql >plaintext-cleaned.sql
psql dbname < plaintext-cleaned.sql
COPY table TO 'data.csv' DELIMITER ',' CSV HEADER;
@danromero
danromero / stripe_last_10_successful_charges.erb
Last active December 29, 2015 09:59
Display last 10 successful charges in a Stripe account.
<ul>
<% Stripe::Event.all(:type => "charge.succeeded").each do |stripe_event| %>
<li><%= Stripe::Customer.retrieve(stripe_event.data.object.customer).description %></li>
<li><%= number_to_currency(stripe_event.data.object.amount / 100.00) %></li>
<% end %>
</ul>
@danromero
danromero / dev.sh
Created January 14, 2014 19:19
Dev bash script—changes from home directory to project directory, pulls latest version of master, boots up vagrant image
#! /bin/bash
cd envoy-web/
git pull
vagrant up
vagrant ssh
@danromero
danromero / hipchat_v2_private_message_curl
Created January 22, 2014 20:59
HipChat API v2 private message via curl
curl -H "Content-Type: application/json" \
-X POST \
-d "{\"message\": \"hello\" }" \
https://api.hipchat.com/v2/user/433057/message?auth_token=4gZZzsXQY75pZHhfnnujKHT8F101LWzcwGPu4jUV
@danromero
danromero / highlight_table_class.js
Created January 28, 2014 22:30
Highlight HTML table cells based on class and value (uses Bootstrap 3 tr/td class stylings)
$("td.days").each(function() {
$this = $(this)
var value = $this.html();
if (value<2) { $this.addClass('success');}
else if (value<5) { $this.addClass('warning');}
else { $this.addClass('danger');}
});
@danromero
danromero / find_last_name
Created February 12, 2014 17:41
Excel/Numbers formula for finding a last name
=RIGHT(A2,LEN(A2)-FIND(" ",A2))
@danromero
danromero / address_parsing
Created February 13, 2014 00:22
Parse string of US address format into component parts
Input:
A1 | 301 Brannan St, San Francisco, CA 94107
Formulas:
B1 | =left(A1,find(",",A1)-1)
C1 | =MID(A1,find(",",A1)+1,find(",",A1)-1)
D1 | =left(right(A1,8),2)
E1 | =right(right(A1,8),5)
Ouput:

Keybase proof

I hereby claim:

  • I am danromero on github.
  • I am dwr (https://keybase.io/dwr) on keybase.
  • I have a public key whose fingerprint is 0E34 D0B8 3363 7A71 05BB C930 90C0 5556 AEF8 5DE7

To claim this, I am signing this object:

Verifying myself: My Bitcoin username is +dwr. https://onename.io/dwr