Skip to content

Instantly share code, notes, and snippets.

@premsh
premsh / revealingModularPattern.js
Created June 25, 2013 18:53
Revealing Modular Pattern
http://www.klauskomenda.com/code/javascript-programming-patterns/#module
@premsh
premsh / singletonModular.js
Last active December 18, 2015 23:19
Singleton Modular Pattern
var NewsWidget = (function () {
var s; // private alias to settings
function somePrivateFunction() {
alert("There are " + s.NumArticles + " articles");
}
return {
settings: {
numArticles: 5,
articleList: $("#article-list"),
@premsh
premsh / ajaxCallWithCustomHeader.js
Created June 25, 2013 18:07
ajax call with additional headers
$(document).ready(function () {
$.ajaxSetup({
headers: { 'Id': '776EF843' }
});
$.ajax({
type: 'GET',
url: 'http://webservice.net/test.svc/test',
dataType: 'json',
@premsh
premsh / allowcrossdomainrequest.cs
Created June 25, 2013 02:50
Cross domain requests for WCF services
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, TenantId"); // TenantId could be anything
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
@premsh
premsh / ajaxCall
Created June 24, 2013 22:45
normal AJAX call to WCF
$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'http://localhost:63751/Service1.svc/json/4',
dataType: 'json',
crossDomain: true,
async: true,
success: function (data) {
jsonData = data;
},
@premsh
premsh / gist:5799268
Created June 17, 2013 18:48
Proxy Web Service
[WebService(Namespace = "Foo")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class GetData : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string GetInfo()
{
@premsh
premsh / CreateSharePointGroup
Created May 16, 2013 22:40
create sharepoint group upon feature activation
const string groupName = "CandidateSigned";
// Creates group
public static void CreateCandidateSignedPermissionGroup(SPWeb web, string groupName, string groupDescription)
{
SPUserCollection users = web.AllUsers;
SPUser owner = web.SiteAdministrators[0];
SPMember member = web.SiteAdministrators[0];
SPGroupCollection groups = web.Groups;
groups.Add(groupName, member, owner, groupDescription);
@premsh
premsh / sp2013_SampleREST
Created May 1, 2013 00:23
Sample REST api call for SharePoint-Hosted app
$.ajax(
{
url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/currentuser",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
$("#message").text('Hello ' + data.d.Title);
},
@premsh
premsh / udpateSharePointSolution.ps1
Created April 15, 2013 22:11
Update SharePoint Solution
$solutionPackageName = "name.wsp"
$SolutoinPackagePath = "path\name.wsp"
Update-SPSolution -Identity $SolutionPackageName -LiteralPath $SolutionPackagePath -Local -GACDeployment
@premsh
premsh / sharePointdeployment.ps1
Created April 15, 2013 22:04
Farm Solution Deployment PowerShell Command
Add-PSSnappin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$SolutionPackageName = "name.wsp"
$SolutionPackagePath = "projectname\name.wsp"
$solution = Get-SPSolution | where-object {$_.name -eq $SolutionPackageName}
if($solution -ne $null)
{
if($solution.Deployed -eq $true)