Skip to content

Instantly share code, notes, and snippets.

/*
Convert GoogleDoc To HTML (on Google Drive )
Converting a Google Document to simple HTML
http://collaborative-tools-project.blogspot.co.uk/2013/06/converting-google-document-to-simple.html
*/
function test_convertGoogleDoc(){
// Iterate through the file iterator for a particular folder
function iterateFolderById() {
var files = DriveApp.getFolderById("0B5eEwPQVn6GOaUt6Vm1GVjZmSTQ").getFiles();
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
var doc = DocumentApp.openById(file.getId());
doc.replaceText("My search string or regex", "My replacement string");
}
@suntong
suntong / Move a Google Doc into another folder.js
Last active December 31, 2015 07:39
move a Google Doc into another folder
/*
How do I move a file to a folder in Google Apps Script?
http://stackoverflow.com/questions/14696514/how-do-i-copy-move-a-file-to-a-folder-in-google-apps-script
Yeah, it is a bit odd that Google does not provide a move method.
But, considering how drive works and that a file can belong to
multiple folders, it makes some sense that you have write your own moves.
I should note that this simple function is exactly that ... simple.
@suntong
suntong / GetFoldersByName.js
Last active July 21, 2018 01:22
Get folder ID by its name
// Get the *first* folder ID by its name
function getFolderByName(folderName) {
var folders = DriveApp.getFoldersByName(folderName);
var folderID = null;
if (folders.hasNext())
folderID = folders.next();
return folderID;
}
/*
Usage:
Adding this script to your doc:
- Tools > Script Manager > New
- Select "Blank Project", then paste this code in and save.
Running the script:
- Tools > Script Manager
- Select "ConvertToMarkdown" function.
- Click Run button.
- Converted doc will be mailed to you. Subject will be "[MARKDOWN_MAKER]...".
@suntong
suntong / Google-Picker_Docs.js
Created December 20, 2013 02:57
Google Picker for Google Docs
// http://stackoverflow.com/questions/20599404/google-picker-for-google-drive
function doGet() {
var app = UiApp.createApplication();
var selectCkH = app.createServerHandler('selectFile');
var closeHandler = app.createServerHandler('closeDocsPicker');
var docsDialog = app.createDocsListDialog().showDocsPicker()//.setInitialView(google.picker.ViewId.FOLDERS)
// .addView(new google.picker.PhotosView()
// .setType(google.picker.PhotosView.Type.FEATURED))
.addCloseHandler(closeHandler)
"two\nlines"
"\"This is in quotes\""
int d = 3, e, f = 5;
byte z = 22;
double pi = 3.14159;
char x = 'x';
z = (byte) f;
@suntong
suntong / test06.sh
Created February 1, 2014 22:12
overlayfs: mounting overlayfs on top of overlayfs
#!/bin/sh
# http://article.gmane.org/gmane.linux.file-systems/54764
#
# The script (test06.sh) makes a read-only overlayfs mount on top of
# another readonly overlayfs mount, repeating this in a loop,
#
# when all the read-only filesystems are mounted, then it mounts another
# overlayfs that uses the last read-only rootdir as lowerdir and a read-write
# filesystem in upperdir,
@suntong
suntong / main.go
Last active August 29, 2015 14:01
// http://play.golang.org/p/FOe85j-O-n
package main
import (
"fmt"
"os"
"time"
)

Challenge: select all the people that are:

  • in the 3rd class
  • under age 10
  • female

A:

train[(train['Age'] < 10) & (train['pclass'] == 3) & (train['sex'] == "female")]