Skip to content

Instantly share code, notes, and snippets.

View kitmenke's full-sized avatar

Kit Menke kitmenke

View GitHub Profile
@kitmenke
kitmenke / GivePrincipalRoleToItem.cs
Created April 9, 2012 14:50
Code to give one role (Read, Contribute, etc) to an SPPrincipal
public static void GivePrincipalRoleToItem(SPWeb web, SPListItem item, SPPrincipal principal, string roleDefinitionName)
{
if (null == principal)
{
throw new ArgumentException(string.Format("Unable to give role '{0}'; passed principal is null.", roleDefinitionName));
}
bool exists = false;
SPRoleAssignment roleAssignment = null;
try
@kitmenke
kitmenke / ProxyHandler.cs
Created July 5, 2012 21:35
An example HTTPHandler which will proxy requests to the specified server and allow AJAX development locally.
public class ProxyHandler : IHttpHandler
{
const string SERVER_URL = "http://dev-server";
#region IHttpHandler Members
public bool IsReusable
{
get { return false; }
}
@kitmenke
kitmenke / GetCurrentUser.js
Created July 5, 2012 21:59
Example AJAX call
$.ajax({
'url': '/_vti_bin/EHI/Users.svc/json/GetCurrentUser',
'dataType': 'json',
'type': 'GET',
'success': function(data) {
self.currentUser(new Employee(data.d));
},
'error': function() {
console.log("Error getting current user.");
}
@kitmenke
kitmenke / mysite
Last active October 9, 2015 11:08
Apache2 Virtualhost Example configuration
<VirtualHost *>
ServerAdmin webmaster@localhost
ServerName mysite
DocumentRoot /home/kit/code/public_html/mysite
<Directory /home/kit/code/public_html/mysite>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
@kitmenke
kitmenke / gist:4953860
Last active December 13, 2015 18:18
Custom JsRender debug tag
/**
* Custom JsRender debug tag
* Log a message and an object to the console.
* Usage: {{debug #parent message='Inside the for loop'/}}
**/
$.views.tags({
debug: function(obj) {
var props = this.props;
// output a default message if the user didn't specify a message
var msg = props.message || 'Debug:';
@kitmenke
kitmenke / ajax.js
Last active December 17, 2015 01:19
JsRender templates for creating SOAP messages to call the QueryEx Search.asmx service
function encodeHTML(str) {
return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&apos;');
}
var queryXml = $('#tmplQueryXml').render({
'QueryText': $('#txtQueryText').val(),
'Count': 100,
'StartAt': 1
});
@kitmenke
kitmenke / HandySafeXmlToSkyWalletCsv.py
Created July 31, 2013 04:14
Convert a HandySafe exported XML file to a CSV file for Sky Wallet to import.
# HandySafeXmlToSkyWalletCsv.py
# Convert HandySafe XML to Sky Wallet CSV
# Save the HandySafe export as test1.xml (hard coded below)
# Then, run: python HandySafeXmlToSkyWalletCsv.py > output.txt
# Tested using Python 2.7.4
# Author: Kit Menke (@kitmenke) on 7/30/2013
import csv, xml.etree.ElementTree as ET
# CHANGE ME: change HANDY_SAFE_XML with the name of your exported HandySafe XML file
@kitmenke
kitmenke / WebForm1.aspx.cs
Created August 27, 2013 18:31
Example for calling the Microsoft Translator AJAX API using jQuery
private static AdmAuthentication _admAuth = new AdmAuthentication(AdmConstants.CLIENT_ID, AdmConstants.CLIENT_SECRET);
protected void Page_Load(object sender, EventArgs e)
{
txtAuthToken.Text = _admAuth.GetAccessToken().access_token;
txtAuthExpires.Text = _admAuth.GetAccessToken().expires_in;
}
@kitmenke
kitmenke / getcurrentuser.html
Created November 1, 2013 02:57
An example of getting the current user via SharePoint's client object model
<script type="text/javascript">
function CustomExecuteFunction() {
var self = this;
self.context = new SP.ClientContext.get_current();
self.web = context.get_web();
self.currentUser = web.get_currentUser();
context.load(self.currentUser);
self.asyncSuccess = function(sender, args) {
var user = this.currentUser;
@kitmenke
kitmenke / multiemail.js
Created November 5, 2013 22:07
Knockout Validation multiple email address
ko.validation.rules['multiemail'] = {
validator: function (val, validate) {
if (!validate) { return true; }
var isValid = true;
if (!ko.validation.utils.isEmptyVal(val)) {
// use the required: true property if you don't want to accept empty values
var values = val.split(';');
$(values).each(function (index) {
isValid = ko.validation.rules['email'].validator($.trim(this), validate);