Skip to content

Instantly share code, notes, and snippets.

Pete Hawkins phawk

Block or report user

Report or block phawk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
phawk / graphql.js
Created Aug 23, 2019
Lambda Shopify graphql proxy endpoint
View graphql.js
const https = require("https")
const fetch = require("isomorphic-fetch")
const Account = require("./models/account")
const authenticated = require("./lib/auth")
exports.handler = authenticated(async (event, context) => {
const { id: shopId, shopifyToken } = context.account
try {
const resp = await fetch(`https://${shopId}/admin/api/2019-07/graphql.json`, {
phawk / authentication.js
Created Aug 23, 2019
Lambda HoC for authenticating requests with dynamoDB
View authentication.js
const Account = require("../models/account")
module.exports = (handler) => async (event, context) => {
let auth = event.headers.authorization
auth = auth.replace(/^Basic\s/, "")
auth = Buffer.from(auth, 'base64').toString()
const [id, token] = auth.split(":")
const account = await Account.get({ id })
phawk / getToken.js
Created Aug 23, 2019
Shopify exchange OAuth code for token and create user account
View getToken.js
const crypto = require("crypto")
const querystring = require("querystring")
const fetch = require("isomorphic-fetch")
const Account = require("./models/account")
exports.handler = async (event, context) => {
const { shop, hmac, code, timestamp } = event.queryStringParameters
const apiKey = process.env.SHOPIFY_API_KEY
const apiSecret = process.env.SHOPIFY_API_SECRET
phawk / install.js
Created Aug 23, 2019
Shopify install lambda
View install.js
exports.handler = async (event, context) => {
const shop =
const redirectUri = event.queryStringParameters.redirect
const apiKey = process.env.SHOPIFY_API_KEY
const scopes="read_content,write_content,read_products,read_themes,write_themes"
if (shop) {
const installUrl = 'https://' + shop +
'/admin/oauth/authorize?client_id=' + apiKey +
'&scope=' + scopes +
phawk / payhere_webhooks_controller.rb
Created Feb 20, 2019 PayHere Webhooks integration
View payhere_webhooks_controller.rb
module Events
class PayhereWebhooksController < ApplicationController
skip_before_action :authenticate_user!
skip_before_action :verify_authenticity_token
def create
return head 401 unless valid_signature?
if payment_params[:status] == "success"
user = find_or_create_user
View payhere_embed_demo.html
<button data-payhere-embed="">Subscribe now</button>
<script src=""></script>
phawk / NSImage+QuickLook.swift
Created Feb 15, 2018
Swift macOS generate image previews of files on disk
View NSImage+QuickLook.swift
import AppKit
import QuickLook
extension NSImage {
static func previewForFile(path fileURL: URL, ofSize size: CGSize, asIcon: Bool) -> NSImage? {
let dict = [
kQLThumbnailOptionIconModeKey: NSNumber(booleanLiteral: asIcon)
] as CFDictionary
phawk / non-single-use.html.erb
Created Dec 4, 2017
Single use classes HTML bloat
View non-single-use.html.erb
<%= page_title("Account") %>
<%= render 'my_account/shared/header', current_section: "rewards" %>
<div class="container">
<div class="tab-content">
<div class="grid">
<div class="col-2-3">
<h3 class="heading">Bonus Points <span>2/8 bonus points earned</span></h3>
<p>Get even greater value from your rewards points by redeeming them against these special offers below. These offers are a one time only use and only unlock as and when you reach the Rewards Level required to do so.</p>
View dbx-resp.json
"entries": [{
".tag": "folder",
"name": "flashed",
"path_lower": "/flashed",
"id": "id:aJSxKm7T6cAAAAAAAAAAAg"
}, {
".tag": "file",
"name": "tumblr_nrjpzx4aAl1t7ikjqo1_1280.jpg",
"path_lower": "/flashed/tumblr_nrjpzx4aal1t7ikjqo1_1280.jpg",
phawk / dropbox-cursor-issues.rb
Last active Dec 28, 2015
Dropbox cursor issues
View dropbox-cursor-issues.rb
# The examples are in Ruby using RestClient (an http library)
# Already have a cursor for this user retreived the last time I called /2/files/list_folder/continue
# 1AAFFUB2KR3h0S0317__4aWVmvEQwDmIR2fdxsGL4cZGqiZjavby0HkZT70COXZm6XlswiDTQXSM7ir1qZX9uGoKGI9FbI7dSiquLv9-shzV8qOb126UToXHiKfe_oDFRzCg
resp =
cursor: "1AAFFUB2KR3h0S0317__4aWVmvEQwDmIR2fdxsGL4cZGqiZjavby0HkZT70COXZm6XlswiDTQXSM7ir1qZX9uGoKGI9FbI7dSiquLv9-shzV8qOb126UToXHiKfe_oDFRzCg"
You can’t perform that action at this time.