Skip to content

Instantly share code, notes, and snippets.

View mikekunze's full-sized avatar

Mike Kunze mikekunze

View GitHub Profile
@mikekunze
mikekunze / .gitignore
Created June 14, 2013 00:06
simple .gitignore for webstorm project. ignore npm, bower, and webstorm content
public/components
node_modules
.idea
@mikekunze
mikekunze / upload.js
Last active December 19, 2015 15:58
Simple uploader Express route for CKEditor's Image Upload feature
fn = function(req, res) {
var dest, fileName, fs, l, tmpPath;
fs = require('fs');
tmpPath = req.files.upload.path;
l = tmpPath.split('/').length;
fileName = tmpPath.split('/')[l - 1] + "_" + req.files.upload.name;
dest = __dirname + "/public/uploads/" + fileName;
@mikekunze
mikekunze / getListTypeByTitle.coffee
Created July 23, 2013 18:53
This script is sample code for getting the itemType token from a SharePoint 2013 list.
user = "domain\\username"
pass = "password"
url = "http://sharepoint/siteCollection"
list = "listName"
request = require 'request'
getListTypeByTitle = (title, cb)->
processRequest = (err, res, body)->
cb(err, JSON.parse(body).d.ListItemEntityTypeFullName)
@mikekunze
mikekunze / getListContext.coffee
Created July 23, 2013 19:06
This script will get the authenticated context info from a SharePoint 2013 list.
user = "domain\\username"
pass = "password"
url = "http://sharepoint/siteCollection"
list = "listName"
request = require 'request'
getListContext = (title, cb)->
processRequest = (err, res, body)->
cb(err, JSON.parse(body).d.GetContextWebInformation.FormDigestValue)
@mikekunze
mikekunze / addListItemByTitle.coffee
Created July 23, 2013 19:47
This is an example of how to post an item to a SharePoint 2013 list. You must have the list itemType and list contextinfo tokens available prior to adding items to SharePoint via REST API.
user = "domain\\username"
pass = "password"
url = "http://sharepoint/siteCollection"
list = "listName"
# These two variables need to be obtained from the sharepoint server
itemType = "SP.Data.SomethingListItem"
context = "some really long hex string value"
# Define the request fn
@mikekunze
mikekunze / addAttachment.coffee
Created July 26, 2013 16:11
This is an example of how to post a file attachment to a SharePoint 2013 list item. You must have the list contextinfo token available prior to adding attachments to a list item.
user = "domain\\username"
pass = "password"
url = "http://sharepoint/siteCollection"
list = "listName"
spItemId = 1
fileName = "filename.file"
data = "" # The file data should be pulled from the fs using { encoding: null }
# This is pulled from REST using ./_api/contextinfo
context = "some really long hex string value"
<table cellspacing="0" width="100%" class="ms-rteTable-default">
<tbody>
<tr class="ms-rteTableEvenRow-default" style="background-color: #b70101;">
<td class="ms-rteTableEvenCol-default" style="width: 50%;">
<h1 style="color:white !important;">Description</h1>
</td>
<td class="ms-rteTableOddCol-default" style="width: 50%;">
<h1 style="color:white !important;">Contact</strong></h1>
</td>
</tr>
<div class="progress" id="progress" style="width:100%">
<div class="bar bar-success" style="width:100%"><p id=progressDisplay>0%</p></div>
</div>
<form enctype="multipart/form-data" action="/mUpload" method="post" id="fileForm">
<input type="file" id="fileField">
<a class="btn btn-small btn-primary" id="addFile">Upload File</a>
</form>
handler = ()->
document.getElementById("fileField").files
# Make sure a file is selected first
if files.length <= 0
alert('choose a file, first')
return
file = files[0]
fd = new FormData()
mUpload = (req, res)->
file = req.files["fileForm"]
tmpPath = file.path
fileName = file.name
dest = __dirname + "/#{fileName}"
fs.readFile tmpPath, (err, data)->
fs.writeFile dest, data, (err)->