Skip to content

Instantly share code, notes, and snippets.

function removeMultipleLineBreaks(element) {
if (!element) {
element = DocumentApp.getActiveDocument().getBody();
}
var parent = element.getParent();
// Remove empty paragraphs
if (element.getType() == DocumentApp.ElementType.PARAGRAPH
&& element.asParagraph().getText().replace(/\s/g, '') == '') {
if (!(parent.getType() == DocumentApp.ElementType.BODY_SECTION
&& parent.getChildIndex(element) == parent.getNumChildren() - 1)) {
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//source file is https://docs.google.com/spreadsheet/ccc?key=0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE
$(function listBooks() {
$.getJSON( "https://spreadsheets.google.com/feeds/list/0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE/od6/public/values?alt=json-in-script&callback=?",
function (data) {
$('div#book-list').append('<ul class="items"></ul>');
$.each(data.feed.entry, function(i,entry) {
var item = '<span style="display:none">' + entry.id.$t + '</span>';
@ronatgithub
ronatgithub / code.js
Created March 12, 2015 22:55
merge multiple documents and remove all extra line breaks using Google Apps Script
function mergeGoogleDocs() {
var folder = DriveApp.getFolderById('0BwqqMAWnXFBhMiJjM6FZakw9b1k'); // set folder ID were we should look for files to merge
var docIDs = [];
var files = folder.getFiles();
while (files.hasNext()){
file = files.next();
docIDs.push(file.getId());
}
@ronatgithub
ronatgithub / code.js
Created March 13, 2015 01:42
Send Google Form by Email using Google Apps Script
/* Send Google Form by Email v2.1 */
/* For customization, contact the developer at amit@labnol.org */
/* Tutorial: http://www.labnol.org/?p=20884 */
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();

Google Drive File Picker Example

This is an example of how to use the Google Drive file picker and Google Drive API to retrieve files from Google Drive using pure JavaScript. At the time of writing (14th July 2013), Google have good examples for using these two APIs separately, but no documentation on using them together.

Note that this is just sample code, designed to be concise to demonstrate the API. In a production environment, you should include more error handling.

See a demo at http://stuff.dan.cx/js/filepicker/google/

@ronatgithub
ronatgithub / gist:5a06f5dbfef4f05ef60e
Last active August 29, 2015 14:17
Google App Script - mail pdf from merged documents
// set time trigger to mergeGoogleDocs() function to run once a day at midnight
function mergeGoogleDocs() {
// set folder ID were we should look for files to merge
var folder = DriveApp.getFolderById('0BwqqMAWnXFBhMmJjM3FZakw2b1k');
var docIDs = [];
var files = folder.getFiles();
while (files.hasNext()){
file = files.next();
docIDs.push(file.getId());
@ronatgithub
ronatgithub / code
Last active July 6, 2017 20:30
HTML Form to send data to google spreadsheet using Google App Script
// the HTML code on your site:
<form id="form" method="get" action="https://script.google.com/macros/s/AKfycbxeKTVlTkqSGLIRphBrzACjuWlfmejbPIG7NqBxx-7Us7lnqLw/exec" accept-charset="UTF-8">
<input type="text" name="newletter_name" placeholder="Name">
<input type="text" name="newletter_email" placeholder="Email">
<input type="submit" value="Subscribe"/>
</form>
// and here the google apps script:
function pullJSON() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheet = ss.getActiveSheet();
var url="http://example.com/feeds?type=json"; // Paste your JSON URL here
var response = UrlFetchApp.fetch(url); // get feed
var dataAll = JSON.parse(response.getContentText()); //
function getJSON(aUrl,sheetname) {
//var sheetname = "test";
//var aUrl = "http://pipes.yahoo.com/pipes/pipe.run?_id=286bbb1d8d30f65b54173b3b752fa4d9&_render=json";
var response = UrlFetchApp.fetch(aUrl); // get feed
var dataAll = JSON.parse(response.getContentText()); //
var data = dataAll.value.items;
for (i in data){
data[i].pubDate = new Date(data[i].pubDate);
data[i].start = data[i].pubDate;
}
@ronatgithub
ronatgithub / index.html
Last active August 29, 2015 14:26 — forked from nolanlawson/index.html
PouchDB putAttachment
<html>
<body>
<h1>Look in the console</h1>
<script src="//cdn.jsdelivr.net/pouchdb/3/pouchdb.min.js"></script>
<script>
var db = new PouchDB('mydb');
var myBase64String = btoa('foobar');
db.putAttachment('mydoc', 'myattachment.png', myBase64String, 'image/png').then(function () {
return db.get('mydoc', {attachments: true});
}).then(function (doc) {