Skip to content

Instantly share code, notes, and snippets.

@piercemoore
piercemoore / TrimWhitespace.js
Last active December 14, 2015 18:19
Trim ALL tabs, newlines, and unnecessary whitespace from a string in Javascript, simple extension to the String prototype
// For the purposes of this gist, assume we have declared the variable str and it is actually a string.
var str = "This is my awesome string. \n I love strings. \n\t\t\t Stringy string string! \n\t\t\t\tWhat??";
// Regex to remove all tabs and newlines.
str = str.replace(/[\t]|[\n]/gm, '');
// Regex to replace all sets of 2 or more space characters with a single space
str = str.replace(/\s{2,}/g, ' ');
// Regex to remove all HTML comments
@piercemoore
piercemoore / Default.sublime-keymap.json
Last active December 14, 2015 04:29
Helpful Sublime Text keymappings and settings
[
{
"keys": [
"alt+g"
],
"command": "toggle_setting",
"args": {
"setting": "gutter"
}
},
@piercemoore
piercemoore / JavascriptBenchmarkUsage.html
Last active December 12, 2015 07:58
This set of functions, when placed in the correct places, will help you find bottlenecks without having to dive into Chrome's Inspector or Mozilla's Firebug.
<html>
<head>
// Blah Blah Blah
</head>
<body>
<script type="text/javascript">
/**
* We make absolutely positive that the first thing on the stack is our timer starting.
*/
// And away we go!
@piercemoore
piercemoore / ProfanityCounter.sh
Created January 30, 2013 23:13
A command to see how much profanity your team has used in all the commit messages for a repository.
git log --pretty=format:'%s' | tr '[:upper:]' '[:lower:]' | tr '[:space:]' '\n' | sort | uniq -c | sort -nr | grep -iE "(fuck|shit|bitch|damn|hate|ugly|stupid|asshole|moron|eff|worthless|piss)"
@piercemoore
piercemoore / Handlebars.html
Last active December 11, 2015 16:08
Comparison of HTML structure to Handlebars template
<script type="x-handlebars-template" id="messages_messageListItem">
<div class="list">
<div class="sub">
<div class="subject">
{{subject}}
</div>
<div class="notification">
{{unread}}
</div>
<div class="message">
@piercemoore
piercemoore / notification_increment.js
Created January 21, 2013 23:04
Increment Notification count
$(function() {
var badge_unreadMessages = $("#unread_message_count");
// Script to check for notifications runs
// If the script comes back with new notifications:
badge_unreadMessages.text( parseInt( badge_unreadMessages.text() ) + 1 );
});
@piercemoore
piercemoore / medianet_JSON.js
Created December 11, 2012 17:48
Example displaying differences in XML and JSON - JSON Side
{
"Success": true,
"ResultsReturned": 1,
"TotalResults": 1065493,
"Artists": [
{
"MnetId": "1097",
"Name": "Alicia Keys",
"Images": {
"Artist180x80": "http://images.mndigital.com/artists/000/001/097/b.jpeg",
@piercemoore
piercemoore / print_r_alternative.php
Last active October 12, 2015 09:18
Recurse through an object and display formatted contents
<?php
private function dig( $obj , $level = 0 ) {
$return = "";
$tabs = str_repeat( "\t" , $level );
foreach( $obj as $k => $v ) {
if( self::keyed( $v ) ) {
$return .= $tabs . "$k object: \n";
@piercemoore
piercemoore / feedback.js
Created November 3, 2012 01:23
Mongoose Schema to store GitHub Issues
var githubSchema = new Schema({
"url": String,
"html_url": String,
"number": Number,
"state": String,
"title": String,
"body": String,
"user": {
"login": String,
"id": Number,
@piercemoore
piercemoore / pm_codepage.php
Created October 3, 2012 07:17
Code page for PierceMoore.com
class Snippets {
public $snips;
function __construct() {
$this->snips = new stdClass;
}