Skip to content

Instantly share code, notes, and snippets.

View Sinetheta's full-sized avatar

Kevin Attfield Sinetheta

View GitHub Profile
# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
@Sinetheta
Sinetheta / bookmarklet-debughtml.js
Created February 21, 2013 19:58
HTML debugging with css.
// based on Ben Alman's Debugging with Less https://github.com/cowboy/benalman.com-idea/commit/d99edd33a5000875776393e28afa412496260850
// using Paul Irish's Bookmarklet: Inject New Css Rules http://paulirish.com/2008/bookmarklet-inject-new-css-rules/
(function (){
var newcss = '';
var tags = [['H1','#f00'],['H2','#0a0'],['H3','#00f'],['H4','#f0f'],['H5','#0ff'],['H6','#0ff'],['P','#0aa'],['LI','#aa0'],['A','#000']];
var createMarker = function(tag, bg){
return tag + ':before {padding: 0 4px; margin-right: 4px; color: #fff;content: "' + tag + '";background: ' + bg + ';} ';
};
for (var i = 0; i < tags.length; i++) {
@Sinetheta
Sinetheta / trim.js
Created March 4, 2013 01:14
NodeJS connect middleware for removing trailing slashes http://stackoverflow.com/a/13443359/848249
app.use(function(req, res, next) {
if(req.url.substr(-1) == '/' && req.url.length > 1)
req.url.slice(0, -1);
next();
});
function string_to_slug(str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@Sinetheta
Sinetheta / _.templateSettings.js
Created May 10, 2013 20:10
Underscore templates with moustaches
_.templateSettings = {
evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g
};
@Sinetheta
Sinetheta / image-utilities.js
Created May 15, 2013 15:28
image related utilities
function trimExtension(str) {
return str.substr(0, str.lastIndexOf('.'));
}
@Sinetheta
Sinetheta / README.md
Last active July 14, 2016 13:45
Using Yeoman to make a SharePoint 2010 project with REST.

Setting up a new Yeoman project using the sp2010 rest emulator:

  1. Create a new Yeoman project, eg: $ yo webapp my-project.
  2. Install the SharePoint 2010 rest emulator $ npm install sp2010-rest --save-dev.
  3. Add the rest emulator as middleware to any connect servers in your project's [Gruntfile.js][Gruntfile].
  4. Create a 'lists' folder in your project, and fill it with a copy of the json REST response (eg: /_vti_bin/listdata.svc/Documents -> [demo-list.json][json]) for any SharePoint lists you would like to emulate.

Deploying a Yeoman project to a sp2010 server:

  1. Map a network drive to SharePoint.
@Sinetheta
Sinetheta / master.master
Last active December 22, 2015 02:09
Exposing user data through javascript on a SharePoint 2010 master page.
<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SPSWC:ProfilePropertyLoader runat="server"/>
<script>
CurrentUser = {
UserName: '<SPSWC:ProfilePropertyValue PropertyName="UserName" TitleMode="true" runat="server" />',
FirstName: '<SPSWC:ProfilePropertyValue PropertyName="FirstName" TitleMode="true" runat="server" />',
Lastname: '<SPSWC:ProfilePropertyValue PropertyName="LastName" TitleMode="true" runat="server" />',
PictureURL: '<SPSWC:ProfilePropertyValue PropertyName="PictureURL" TitleMode="true" runat="server" />',
@Sinetheta
Sinetheta / footnoteLinks.js
Last active December 23, 2015 09:09
Add a footnotes style list of links at the bottom of a page. Hide with class `.printOnly`. Depending on your environment, it may be necessary to scope the target container (eg: avoid including navigation links).
@Sinetheta
Sinetheta / custom-matchers.coffee
Last active August 29, 2015 14:22
custom-matchers.coffee
customMatchers =
toChange: (util, customEqualityTesters) ->
compare: (actual, expected) ->
before = expected()
actual()
after = expected()
result =
pass: !util.equals(before, after, customEqualityTesters)
if result.pass
result.message = "Expected result not to change, but went from #{before} to #{after}"