Skip to content

Instantly share code, notes, and snippets.

@loickreitmann
loickreitmann / getQuerystringParamByName.js
Created December 6, 2010 22:13
JS function to grab a QS param
function getQuerystringParamByName(name) {
var regexS, regex, results;
regexS = "[\\?&]" + name + "=([^&#]*)";
regex = new RegExp(regexS);
results = regex.exec(location.href);
if (results === null) {
return null;
} else {
return (results[1] !== '') ? results[1] : null;
}
@loickreitmann
loickreitmann / doCookie.js
Created December 6, 2010 22:21
JS function to get or set a cookie
/**
* doCookie: function to get or set a cookie
* @param name (string): cookie name
* @param value (string - optional): cookie value to set
* @param options (object - optional): possible options are
* - expires: (number of days | proper datetime string)
* - path: (string)
* - domain: (string)
*/
function doCookie(name, value, options) {
@loickreitmann
loickreitmann / String.toCamelCase.js
Created April 14, 2011 22:51
Simple String method to convert a string to camel case (i.e, "This is my string!? Dashes - removed !@#$%^&*()(.+=;':[]}{<>|,./\"" converts to "thisIsMyStringDashesRemoved".
/**
* toCamelCase: converts string to camel case
*/
String.prototype.toCameCase = function () {
return this.replace(/^\s+|\s+$/g, "")
.toLowerCase()
.replace(/(\s[a-z0-9])/g, function ($1) {
return $1.replace(/\s/, '').toUpperCase();
})
.replace(/\W/g, '');
@loickreitmann
loickreitmann / String.trim.js
Created April 14, 2011 22:54
String method to remove leading and trailing white space.
/**
* trim: removes leading and trailing white space
*/
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, "");
};
@loickreitmann
loickreitmann / String.toDashed.js
Created April 14, 2011 23:11
Converts a string to dashed.
/**
* toDashed: converts string to dashed
*/
String.prototype.toDashed = function () {
return this.replace(/^\s+|\s+$/g, "")
.toLowerCase()
.replace(/-/g, '')
.replace(/(\s[a-z0-9])/g, function ($1) {
return $1.replace(/\s/, '-');
})
@loickreitmann
loickreitmann / String.toUnderscored.js
Created April 14, 2011 23:19
Converts string to underscored.
/**
* toUnderscored: converts string to underscored
*/
String.prototype.toUnderscored = function () {
return this.replace(/^\s+|\s+$/g, "")
.toLowerCase()
.replace(/_/g, '')
.replace(/(\s[a-z0-9])/g, function ($1) {
return $1.replace(/\s/, '_');
})
@loickreitmann
loickreitmann / String.stripTags.js
Created April 22, 2011 19:13
String function to remove HTML tags from the string
/**
* stripTags: removes HTML tags from a string
* @return String
*/
String.prototype.stripTags = function () {
return this.replace(/<[^<>]+>/g, ' ').replace(/\s{2,}/g, ' ');
};
@loickreitmann
loickreitmann / web-server-user.php
Created May 12, 2011 17:36
Output web server user account on a PHP web page
<?php echo(exec("whoami")); ?>
@loickreitmann
loickreitmann / twitter_feed.html
Created April 12, 2012 00:38
HTML example that pulls a twitter user's feed, using some jQuery animations
<!DOCTYPE html>
<html>
<head>
<title>Twitter feed consumption example</title>
<style>
.main {
margin: 0 auto;
position: relative;
width: 328px;
height: 302px;
@loickreitmann
loickreitmann / String.times.js
Created May 8, 2012 20:46
String.times: String method to repeat a string n times
String.prototype.times = function( n ) {
return Array.prototype.join.call( { length : n + 1 }, this );
};