Skip to content

Instantly share code, notes, and snippets.

View Sinetheta's full-sized avatar

Kevin Attfield Sinetheta

View GitHub Profile
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 / 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();
});
@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++) {
# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
<?php
function themename_customize_register($wp_customize){
$wp_customize->add_section('themename_color_scheme', array(
'title' => __('Color Scheme', 'themename'),
'priority' => 120,
));
// =============================
@Sinetheta
Sinetheta / time_zone.js
Created November 30, 2012 19:57
JS: current timezone offset
var currentTimeZoneOffsetInHours = (new Date()).getTimezoneOffset()/60;
@Sinetheta
Sinetheta / jquery-whenReady.js
Created November 29, 2012 22:35
$.whenReady wait for arbitrary target to be ready
$.whenReady = function(target, delay) {
var dfd = $.Deferred();
var look = window.setInterval(function() {
var $target = $(target);
if($target.length) {
dfd.resolve($target);
window.clearInterval(look);
}
}, delay || 10);
return dfd;
@Sinetheta
Sinetheta / log.js
Created November 15, 2012 22:32 — forked from cowboy/log.js
JavaScript: (madness?).log()
/*
* (madness?).log()
*
* Copyright (c) 2012 Kevin Attfield
* Licensed under the MIT license.
*/
Object.prototype.log = function(){
console.log(this.valueOf());
return this;
@Sinetheta
Sinetheta / search_sharepoint.html
Created May 16, 2012 17:28
JS: jQuery Sharepoint search replacement
/**********************************************************************
OOTB Search control looks something like this:
<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" Version="4"/>
</asp:ContentPlaceHolder>
We can replace it with either static inputs:
@Sinetheta
Sinetheta / target_user.js
Created April 5, 2012 03:02
JS: SharePoint target user by idir
var GetUserProfileByName = function (accountName) {
var soap = '';
accountName = accountName || ''; //Blank accountName returns results for current user
soap += '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
soap += ' <soap12:Body>';
soap += ' <GetUserProfileByName xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">';
soap += ' <accountName>' + accountName + '</accountName>';
soap += ' </GetUserProfileByName>';
soap += ' </soap12:Body>';
soap += '</soap12:Envelope>';