Skip to content

Instantly share code, notes, and snippets.

View martyndavies's full-sized avatar

Martyn Davies martyndavies

View GitHub Profile
<template>
<div>
<div class="row">
<div class="col s12 center-align">
<h1><i class="medium material-icons">verified_user</i> Login</h1>
</div>
</div>
<div class="row" v-if="request.token === ''">
<form v-on:submit.prevent class="col s12">
<div class="row center-align">
#!/usr/bin/node
if (process.env.NODE_ENV != 'production') require('dotenv').config();
// Set up Algolia
const algolia = require('algoliasearch');
const client = algolia(
process.env.AG_APPLICATION_ID,
process.env.AG_API_WRITE_KEY
);
index.addObject(object, function(err, content) {
index.waitTask(content.taskID, function(err) {
if (!err) {
// Create an object of the input text, source lang and target lang
let objectToTranslate = {
text: content.description_en, // The words to be translated
source: 'en', // The language they are in
target: 'es' // The language you want them to be
};
SELECT sum(query_count)
FROM ((
SELECT query_count
FROM rollups_5min
WHERE timestamp >= $1 AND timestamp < $2 AND app_id = $3
) UNION ALL (
SELECT query_count
FROM rollups_1day
WHERE timestamp >= $1 AND timestamp < $2 AND app_id = $3
)) a...
@martyndavies
martyndavies / rollup.sql
Created April 6, 2018 16:44
Example of a Postgres rollup
CREATE OR REPLACE FUNCTION compute_5min_rollups(start_time TIMESTAMP, end_time TIMESTAMP)
RETURNS void LANGUAGE PLPGSQL AS $function$
BEGIN
EXECUTE $$
INSERT INTO rollups_5min
SELECT
date_trunc('seconds', (timestamp - TIMESTAMP 'epoch') / 300) * 300 + TIMESTAMP 'epoch' AS minute,
app_id,
timestamp,
count(*) AS query_count,
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var sendgrid = require('sendgrid')(api_key);
var moment = require('moment'); // I use this for time cos it's ace
var userInfo = require('./test.json'); // for example purposes this would be the JSON you sent me, you would probably be getting this from a DB or via another call...
var email = new sendgrid.Email({to: userInfo.emailData.email}); // Set up the initial email object, we're sending to Andy.
var timeToSend = moment(userInfo.send_time).unix(); // Scheduled send takes a UNIX timestamp, I used MomentJS to make it
email.setSendAt(timeToSend); // Set the scheduled send time
email.setUniqueArgs({user: userInfo.User}); // Let's pass the username via a unique arg, you'll get this back via the Event Webhook, helps to uniquify tracking
// This is the example from https://github.com/sendgrid/sendgrid-php#headers
// but slight modifications have been made to include code for IP Pooling
$email = new SendGrid\Email();
$email
->addTo('foo@bar.com')
->addTo('bar@foo.com')
->setFrom('me@bar.com')
->setSubject('Subject goes here')
->setText('Hello World!')
@martyndavies
martyndavies / not-so-big-function.js
Created September 9, 2014 13:06
not-so-big-function.js
function replyWithCard(email, callback){
var cardEmail = new sendgrid.Email({
to: email,
from: process.env.FROM_ADDRESS,
fromname: process.env.FROM_NAME,
subject: process.env.SUBJECT,
html: '<h2>Thanks for requesting a business card!</h2>', // <%body%> tag for text
text: 'Thanks for asking for a business card, sorry I didn\'t have any on me!' // <%body%> tag for html
function replyWithCard(email, callback){
var text_block = "Thanks for asking for a business card, sorry I didn\'t have any on me!\n\n";
text_block += "Here are my details:\n\n";
text_block += "Name: "+process.env.FROM_NAME+"\n";
text_block += "Twitter: "+process.env.TWITTER+"\n";
text_block += "Email: "+process.env.FROM_ADDRESS+"\n\n";
text_block += "You can reply to this email to contact me directly.\n\n";
text_block += process.env.SIGN_OFF+"\n\n";
text_block += process.env.SIGNATURE;