Skip to content

Instantly share code, notes, and snippets.


Eirik Brandtzæg eirikb

View GitHub Profile
eirikb / sp-accordion.js
Created Sep 19, 2012
Accordion for SharePoint
View sp-accordion.js
$('head').append($('<link rel="stylesheet">').attr('href', ''));
$.getScript('', function() {
$.getScript('', function() {
var $collapse = $('<div class="accordion">');
var $tplHead = $('<div class="accordion-heading"><a class="accordion-toggle" data-toggle="collapse">');
var $tplBody = $('<div class="accordion-body collapse"><div class="accordion-inner">');
$('.s4-ba .s4-wpTopTable:has([webpartid])').each(function(i) {
var $wp = $(this);
var $content = $wp.find('[webpartid]');
var $head = $tplHead.clone();
eirikb / noteboardfilter.js
Created Sep 27, 2012
Filtering SharePoint Note Board
View noteboardfilter.js
$(function() {
$('.ms-socialCommentEdit').each(function() {
var $wp = $(this).closest('[webpartid]');
var $search = $('<input>').keyup(function() {
$wp.find('.ms-socialCommentItem').filter(function() {
return $(this).find('.socialcomment-contents').text().toLowerCase().indexOf($search.val().toLowerCase()) >= 0;
View SPGetSPcurrentUser.js
var SPGetSPcurrentUser = function(callback) {
var spuserid = "Error";
var context = new SP.ClientContext.get_current();
// Using this here would make it global, as the function is not called with 'new'
// and this would then point to the global object, window
// = context.get_web();
var website = context.get_web();
var currentUser = website.get_currentUser();
View global.asax.cs
protected void Application_PreRequestHandlerExecute()
if (!(Context.Handler is IRequiresSessionState)) return;
var authenticationCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (authenticationCookie == null) return;
var authenticationTicket = FormsAuthentication.Decrypt(authenticationCookie.Value);
if (authenticationTicket == null || authenticationTicket.Expired) return;
eirikb / SharePointHack.cs
Created Apr 24, 2013
Automatically re-load DLL file and invoke external method with SPWeb as parameter. Re-run on DLL re-build
View SharePointHack.cs
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.SharePoint;
namespace SharePointHack
public class Program : MarshalByRefObject
View IsNumeric.cs
using System;
using System.Linq;
public static class IsNumericExtension
public static bool IsNumeric(this string orig)
return orig.Length > 0 && orig.ToCharArray().All(Char.IsNumber);
eirikb / index.html
Last active Dec 20, 2015
Komplett-sort 2000
View index.html
<p>Lagre som bookmarks/favoritter:</p>
<a href="javascript:$('div[class*=prod]').sort(function(a,b){function d(x){var d=$(x).find('.value').text().match(/\d+/);if(!d)return 0;return parseInt(d[0],10)};return d(b)-d(a)}).each(function(i){$('div[class*=prod]').eq(i).replaceWith(this)});">Komplettsalg - prosent</a>
<a href="javascript:$('div[class*=prod]').sort(function(a,b){function d(x,y){var d=$(x).find(y).text().replace(/\./g,'').match(/\d+/);return d?parseInt(d[0]):0}function dd(x){return d(x,'.priceBefore')-d(x,'.price')}return dd(b)-dd(a)}).each(function(i){$('div[class*=prod]').eq(i).replaceWith(this)});">Komplettsalg - prisforskjell</a>
eirikb / imgur-oauth-test.html
Last active Jun 17, 2020
Post to imgur using oauth (api v3) on a static (no server) site
View imgur-oauth-test.html
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>imgur oauth</title>
<script src=""></script>
$(function () {
var extractToken = function(hash) {
View OpenBinaryDirect.cs
public static FileInformation GetFile(ClientContext clientContext, string fileRef)
using (var clientContextHack = new ClientContext(clientContext.Url))
return File.OpenBinaryDirect(clientContextHack, fileRef);
eirikb / dep.js
Created Jun 24, 2014
View dep.js
var d={a:1,b:2},f=function(a,b){return a+b};f.apply(null,(''+f).match(/function[^(]*\(([^)]*)\)/)[1].split(/,\s*/).map(function(x){return d[x]}))
You can’t perform that action at this time.