Skip to content

Instantly share code, notes, and snippets.

View reganstarr's full-sized avatar

Regan Starr reganstarr

View GitHub Profile
var timestamp = Math.floor(new Date() / 1000);
// adapted from http://stackoverflow.com/a/1349426/5573841
function generateRandomString(desiredLengthOfRandomString) {
var result = '';
var possibleCharactersForRandomString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < desiredLengthOfRandomString; i++ )
result += possibleCharactersForRandomString.charAt(Math.floor(Math.random() * possibleCharactersForRandomString.length));
return result;
}
var string = "This is a string";
var encodedString = new Buffer(string).toString('base64');
var twitterHandle = "";
var bestAvailableImage = "";
if(input.user_twitter_link){
var indexOfLastSlash = input.user_twitter_link.lastIndexOf('/');
twitterHandle = input.user_twitter_link.substring(indexOfLastSlash + 1);
twitterHandle = '(@' + twitterHandle + ')';
}
if(input.hidpi_image){
var apiUrl = 'ENTER_THE_API_URL_HERE';
var data = JSON.stringify({
"key1": "value1",
"key2": "value2"
});
fetch(apiUrl, {
method: 'POST',
body: data,
// You can find all three of these in the "Account Details" section of your Cloudinary Dashboard.
var cloudinaryCloudName = "";
var cloudinaryApiKey = "";
var cloudinaryApiSecret = "";
// Upload a semi-transparent PNG file to your Cloudinary account. This semi-transparent image will be used as the watermark. Then, enter the name (Public ID) of that image below. Learn more at http://cloudinary.com/blog/adding_watermarks_credits_badges_and_text_overlays_to_images
var watermarkImageName = "";
var termsNameArray = input.termsName.split(",");
var termsTaxonomyArray = input.termsTaxonomy.split(",");
for (var i = 0; i < termsNameArray.length; i++) {
if(termsTaxonomyArray[i] !== 'post_tag'){
termsNameArray.splice(i, 1);
}
}
var output = {};
/*To get the Trello checklist ID...
1. Open the card that contains the checklist
2. In the right sidebar of the card, click on "Share and more"
3. Click "Export JSON"
4. Select all of that JSON and Copy it to your clipboard
5. Go to http://www.jsoneditoronline.org/
6. Paste in the JSON in the box on the left
7. Click the right arrow [>] button
8. On the right side, scroll down until you see the "checklists" key, then click the arrows to expand that section
9. Use the "name" key find the correct checklist, then copy the "id" value of that checklist
/*
EXAMPLE:
input.tweetContent = This is a tweet about Zapier that mentions @zapier twice as well as reganstarr.
*/
var commaSeperatedTwitterUsernames = "Zapier,ReganStarr";
// You'll need to change input.tweetContent to match whatever input mapping you defined in the "Input" section of Zapier. (https://zapier.com/help/code/#how-does-it-work)
var tweetContent = input.tweetContent;
var username = '';
var password = '';
var encoded_credentials = new Buffer(username + ':' + password).toString('base64');
fetch('https://example.com', { method: 'POST', headers: {'Authorization': 'Basic ' + encoded_credentials} })
.then(function(res) {
return res.json();
})
.then(function(body) {