Skip to content

Instantly share code, notes, and snippets.

/**
* NEVER BLOCKING LOOP : implementation of the infamous setTimeout 0 hack, with time checking in order to guarantee fluidity without sacrificing execution speed.
*
* USAGE :
* var array = ["a way too big array that is heavy to process"]
* optimizedFor({
* nbIterations: array.length,
* each:function( index ) {
* doSomethingUsefulWith( array[ index ] );
* },
@Aymkdn
Aymkdn / bookmarklet
Created October 24, 2012 14:22
Bookmarklet to show all the JS scripts into a page
javascript:(function(){function ajax(b){if(typeof XMLHttpRequest==="undefined"){XMLHttpRequest=function(){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(c){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(c){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(c){}throw new Error("This browser does not support XMLHttpRequest.")}}var a=new XMLHttpRequest();if(!b.url){throw new Error("You must define 'url'")}a.open("GET",b.url);a.onreadystatechange=function(){if(a.readyState===4){if(a.status===200){var c=(a.responseXML?a.responseXML:a.responseText);if(typeof b.success==="function"){b.success(c,b)}}if(typeof b.after==="function"){b.after()}}};a.send()}var s=document.getElementsByTagName("SCRIPT"),tx="",sr=[],i,t;for(i=0;i<s.length;i++){with(s.item(i)){t=text;if(t){tx+=t}else{sr.push(src)}}}var __loadedScript=sr.length;with(window.open()){document.write('<textarea id="t">'+tx+"</textarea>");for(var i=0;i<sr.length;i++){ajax({url:sr[i],success:function(a,b){document.getElementById("t").value+="
@Aymkdn
Aymkdn / getid.js
Created October 21, 2015 06:42
Find the User ID from the User Information List in Sharepoint
// http://aymkdn.github.io/SharepointPlus/symbols/%24SP%28%29.html#.getUserInfo
$SP().getUserInfo("domain\\john_doe", function(info) {
if (typeof info === "string") {
console.log("Error:"+info); // there was a problem so we show it
} else
console.log("User ID = "+info.ID)
});
// query the User Information List
$SP().list("User Information List", "http://site.collection/root/dir").get({
@Aymkdn
Aymkdn / Run a web page from a Github project in one click.md
Last active December 10, 2015 18:48
Run a web page from a Github project in one click. See README below.

When you visit a Github project with, for example, a demo.html page you can simply click on the "Run" button and the page will be loaded directly into your browser without the need to download the full git project in the correct directory and play with your browser to find where you downloaded it.

Instructions :

  1. Store the below PHP file to your web server;
  2. Edit the below Greasemonkey file with the URL of your webserver;
  3. Load the Greasemonkey script into your web browser;
  4. Go to any file stored on Github and you'll see a "Run" button just after the "History" button.

Once you did all the steps then you can try it. For example go to https://github.com/prezjordan/dynamo.js/blob/master/test/test.html and you should see the Run button:

@Aymkdn
Aymkdn / LICENSE.txt
Created July 29, 2011 17:29 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@Aymkdn
Aymkdn / tiny_http.js
Created July 12, 2016 06:55
Tiny HTTP Get/Post
/*
m: method ("get", "post")
u: url
c: callback (with 'xhr' as a parameter)
a: async (true / default) or sync (false)
d: post_data (the data to post)
*/
function tiny_http(m,u,c,a,d){var _xhr=new(this.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP");with(_xhr)onreadystatechange=function(){4^readyState||c(_xhr)},open(m,u,a),"post"===m.toLowerCase()?setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"):"",send(d)}
@Aymkdn
Aymkdn / multiple_approve.js
Created September 15, 2016 08:26
Multiple Approve/Reject in Sharepoint 2010 (jQuery + approval.js)
/*! jQuery v3.1.0 | (c) jQuery Foundation | jquery.org/license */
!function(a,b){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c=[],d=a.document,e=Object.getPrototypeOf,f=c.slice,g=c.concat,h=c.push,i=c.indexOf,j={},k=j.toString,l=j.hasOwnProperty,m=l.toString,n=m.call(Object),o={};function p(a,b){b=b||d;var c=b.createElement("script");c.text=a,b.head.appendChild(c).parentNode.removeChild(c)}var q="3.1.0",r=function(a,b){return new r.fn.init(a,b)},s=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,t=/^-ms-/,u=/-([a-z])/g,v=function(a,b){return b.toUpperCase()};r.fn=r.prototype={jquery:q,constructor:r,length:0,toArray:function(){return f.call(this)},get:function(a){return null!=a?a<0?this[a+this.length]:this[a]:f.call(this)},pushStack:function(a){var b=r.merge(this.constructor(),a);return b.p
@Aymkdn
Aymkdn / method1a.js
Last active October 27, 2016 08:02
Examples to retrieve a manager in Sharepoint 2013
// Retrieve Manager for a username
// using REST API
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
var accountName = 'domain\\login';
// I suppose you use jQuery
$.ajax({
url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
@Aymkdn
Aymkdn / Date.parseFrom.js
Created January 30, 2017 11:02
Date.parseFrom() permits to parse a string to a JavaScript Date
/**
* Parse a string to a Date
* @param {String} strDate
* @param {String} format Supported format including YYYY, YY, MM, M, DD, D, with - and / separators
* @return {Date|Throw} the JS Date object, or throw Error("Invalid Date") if strDate is invalid
* @compatibility IE9+
* @example
* Date.parseFrom("1/10/2017", "MM/DD/YYYY"); // -> new Date(2017,0,10)
*/
Date.parseFrom=function(strDate, format) {
@Aymkdn
Aymkdn / CompareLibrairies.js
Created May 18, 2017 08:11
Use node to compare two Sharepoint librairies and copy the source to the destination. It will create the folders and files, but it will also update the Modified date and Modifier author in the destination to match the source
// Command: node index.js "http://my.site.com/my_root/my_source_libary/" "http://my.othersite.com/my_root/my_destination_libary/"
if (process.argv.length !== 4) throw "ERROR: please provide the source and the destination on the command line";
const colors = require('colors');
// load credentials
const credentials = require('../credentials');
const $SP = require('sharepointplus');
const sp = $SP().auth(credentials);
var requestdigest = '';
// contains the references to the items to update in the dest lib