Skip to content

Instantly share code, notes, and snippets.

View vman's full-sized avatar
👨‍💻

Vardhaman Deshpande vman

👨‍💻
View GitHub Profile
@vman
vman / cffor.coffee
Created January 25, 2012 14:42
cffor
#All the hrefs are extracted from all the anchor links on the page and stored in the array 'anchorHrefs'
anchorHrefs = anchor.href for anchor in $("a")
@vman
vman / url.coffee
Created January 25, 2012 14:44
urlcoffee
#Check whether the current web is the root web and if its not, append a "/" to the end.
currentUrl = _spPageContextInfo.webServerRelativeUrl
currentFormattedUrl = if currentUrl is "/" then currentUrl else currentUrl + "/"
alert currentFormattedUrl
@vman
vman / exec.coffee
Created January 25, 2012 16:22
execordelay
#Call the loadCOM function only if the sp.js script is loaded on this page.
ExecuteOrDelayUntilScriptLoaded loadCOM, "sp.js"
var PrintName = function (firstname,lastname) {
///<signature>
///<summary>Print the First Name</summary>
///<param name="name" type="String">First Name</param>
///<returns type="void"/>
///</signature>
///<signature>
///<summary>Print the Full Name</summary>
///<param name="name" type="String">First Name</param>
///<param name="lastname" type="String">Last Name</param>
@vman
vman / testmodule.js
Created May 16, 2012 07:45
functions which will be used for testing with jasmine.
var ModuleToTest = function () {
return {
//Function to Convert a value to Integer with radix 10.
MakeInt: function (value) {
return parseInt(value, 10);
},
//Function to multiply two numbers and return the product.
@vman
vman / mainFileSpec.js
Created May 16, 2012 07:55
code for testing the functions in the mainfile.js
//The "describe" function is used to define the functionality which will be tested for the function.
//It takes 2 parameters: The first is the name of the function and next is an anonymous function which will contain the testing code.
describe("Test Module", function () {
//One describe function can be nested inside another. This is particularly great if you want to test modules which have nested functions.
describe("MakeInt", function () {
//The it function describes one implementation of a function. The syntax is same as describe: first parameter is the description of the implementation and
//the second is an anonymous function which will be used to execute the function to test.
it("Makes strings into integers", function () {
@vman
vman / specrunner.aspx
Created May 16, 2012 08:35
jasmine framework tests
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.1.0/jasmine_favicon.png"/>
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.1.0/jasmine.css"/>
@vman
vman / SandboxRegisterClientScriptBlock.cs
Created August 21, 2012 11:56
SandboxRegisterClientScriptBlock
public static void SandboxRegisterClientScriptBlock(string scriptId, string scriptUrl,Page page)
{
//Add script control.
HtmlGenericControl addJscript = new HtmlGenericControl("script");
addJscript.Attributes.Add("type", "text/javascript");
//Checks if the script is already loaded and if not, load it.
addJscript.InnerHtml = @"function CheckScriptAndLoad() {
//Check if script is loaded. Return true if yes, else return false.
var isScriptLoaded = function (scriptId) {
if (document.getElementById(scriptId) != null) {
@vman
vman / paging.js
Created August 27, 2012 09:02
COM Paging
var listItems; // The list of retrieved items.
var query; // For paging, reuse the same query object.
var targetList; // The list from which to retrieve items.
var clientContext;
function runCode() {
clientContext = new SP.ClientContext();
targetList = clientContext.get_web().get_lists().getByTitle('Announcements');
query = new SP.CamlQuery();
//Specifying the RowLimit will determine how many items will be fetched in one call to the server.
@vman
vman / encode.xsl
Created August 28, 2012 10:47
encode
<xsl:output method="xml" indent="no" encoding="iso-8859-1"/>