Skip to content

Instantly share code, notes, and snippets.

View adamjstevenson's full-sized avatar
🏄‍♂️

Adam Stevenson adamjstevenson

🏄‍♂️
View GitHub Profile
@adamjstevenson
adamjstevenson / postgres_cheatsheet.txt
Created June 24, 2020 23:07
Basic Postgres localhost database import cheatsheet
# Connect to local PG instance
psql -U postgres
# Show databases
\l
# Drop existing database and recreate
drop database DBNAME
create database DBNAME
@adamjstevenson
adamjstevenson / gdax-buy.js
Last active March 10, 2018 23:11
Place a buy order on GDAX
// Place a buy order
function buyOrder(orderSize, currentPrice){
const args = {
'product_id': 'ETH-USD',
'type': 'market',
'side': 'buy',
'size': orderSize
}
gdaxClient.buy(args)
@adamjstevenson
adamjstevenson / send-sms.js
Created March 10, 2018 21:15
Send an SMS with Twilio
// Send SMS notification
function sendSMS(message){
twilioClient.messages.create({
to: process.env.MY_NUMBER,
from: process.env.TWILIO_SMS_NUMBER,
body: message
})
.then(msg => {
// Log the message from Twilio
console.log(msg);
@adamjstevenson
adamjstevenson / gdax-eth.js
Last active March 10, 2018 21:13
Check the price of ETH with GDAX
// Check the price of ETH to determine how much to buy
gdaxClient.getProductTicker(
'ETH-USD'
)
.then(data => {
// Determine what $10 of ETH costs
const price = (10/data.price);
// Return smallest unit available for purchase
const orderSize = price.toString().substr(0,10);
@adamjstevenson
adamjstevenson / lambda.js
Last active March 10, 2018 21:07
Node.js Lambda handler outline
// ... the previous initialization code above
// Declare Lambda handler
const handler = (event, context, callback) => {
// Check the price of ETH to determine how much to buy
// Place a buy order
// Send an SMS notification
@adamjstevenson
adamjstevenson / app.js
Created March 1, 2018 02:40
Setting up a function for Twilio and GDAX
// Use dotenv to load environment variables
require('dotenv').config();
// Load Twilio and GDAX
const twilio = require('twilio');
const gdax = require('gdax');
// Set up GDAX for buying crypto
const gdaxClient = new gdax.AuthenticatedClient(
process.env.GDAX_API_KEY,
@adamjstevenson
adamjstevenson / payout_detail.rb
Created October 22, 2017 19:06
Retrieve balance history for a Stripe Connect payout
# Get the balance transactions from the payout for the payout transactions view
@txns = Stripe::BalanceTransaction.list(
{
payout: params[:id], # The ID of the payout you want transactions for
expand: ['data.source.source_transfer'], # Expand the source_transfer for extra detail
limit: 100
},
{ stripe_account: current_user.stripe_account }
)
@adamjstevenson
adamjstevenson / list_payouts.rb
Created October 22, 2017 18:58
List payouts for a connected account
# Last 100 payouts from the custom account to their bank account
@payouts = Stripe::Payout.list(
{
limit: 100,
expand: ['data.destination'] # Get some extra detail about the bank account
},
{ stripe_account: current_user.stripe_account } # Again, authenticating with the ID of the connected account
)
@adamjstevenson
adamjstevenson / _payments.html.erb
Created October 22, 2017 18:44
A rails payments view
<div class="row">
<div class="col-md-12">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Payment ID</th>
<th>Amount</th>
<th>Net</th>
<th>Created</th>
<th>Actions</th>
@adamjstevenson
adamjstevenson / list_charges.rb
Created October 22, 2017 18:42
List charges for a connected account
# Last 100 charges
payments = Stripe::Charge.list(
{
limit: 100, # The number of charges to retrieve (between 1 and 100)
expand: ['data.source_transfer', 'data.application_fee'] # Expand other objects for additional detail
},
{ stripe_account: current_user.stripe_account } # The Stripe ID of the user viewing the dashboard
)