Skip to content

Instantly share code, notes, and snippets.

View craigpalermo's full-sized avatar

Craig Palermo craigpalermo

View GitHub Profile
@craigpalermo
craigpalermo / gist:47ffa4700eda563a21ab
Created November 11, 2014 05:34
Hide currently displayed Reddit posts that contain badWord in the title
function dontShow(badWord) {
$(".thing").each(function(){
var $parent = $(this);
var title = $parent.children(".entry").children(".title").children("a").html();
if (title && title.indexOf(badWord) > 0) {
console.log(title);
$parent.hide();
}
});
@craigpalermo
craigpalermo / nodejs.conf
Created December 7, 2014 05:10
Apache proxy for NodeJS server on port 3000
<VirtualHost *:80>
ServerName myserver.com
ServerAlias www.myserver.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
@craigpalermo
craigpalermo / similarity.py
Last active August 29, 2015 14:11
Calculate the level of similarity between two strings, on a scale from 0 to 1
"""
Credit to sissi_lauty for this algorithm
Original: http://stackoverflow.com/a/15077476
"""
from math import sqrt
def similarity(x, y):
# find length of shorter of the two strings
n=min(len(x), len(y))
@craigpalermo
craigpalermo / angularjs-file-consolidation.md
Last active March 11, 2018 05:48
Use Grunt tasks to consolidate HTML, CSS, and JS files to improve application performance

Optimizing route load times in AngularJS

Abstract

By consolidating HTML templates, CSS stylesheets, and JavaScript, we can greatly reduce the amount of time spent waiting for requests to retrieve external resources and make transitions between routes appear much smoother.

Advantages of consolidation

@craigpalermo
craigpalermo / focusToSelect.js
Created June 6, 2015 18:37
Select text on input focus
/*
Credit to CSS-Tricks.com ~ https://css-tricks.com/copy-paste-the-web/
*/
$('#ta').on("focus", function(e) {
e.target.select();
$(e.target).one('mouseup', function(e) {
e.preventDefault();
});
});
@craigpalermo
craigpalermo / promise_callback.js
Created August 6, 2015 04:00
JavaScript example of using promises and callbacks
var promiser = function (callback) {
var promise = new Promise(function(resolve, reject){
console.log("Promise created");
window.setTimeout(function(){
resolve("Hello from Promise Land");
}, 3000);
});
promise.then(function(){
callback();
@craigpalermo
craigpalermo / archive_old_files.py
Last active October 4, 2015 05:36
A script that moves all files in current directory that haven't been modified in the desired number of days to a different folder.
from datetime import datetime, timedelta
from sets import Set
import argparse
import sys
import os
import time
import shutil
import re
@craigpalermo
craigpalermo / gist:4ef6ac2a8cf36e288099bd6601c948ae
Created July 24, 2016 11:33
Apache - redirect traffic from subdomain to port on localhost
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName dev.mydomain.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
@craigpalermo
craigpalermo / exponential-backoff.markdown
Last active September 23, 2016 00:21
Exponential Backoff
@craigpalermo
craigpalermo / ls_apache_enabled_servernames.sh
Created December 20, 2016 01:07
Prints ServerName line of each enabled Apache site configuration (so you can see which subdomains you're hosting)
ls /etc/apache2/sites-enabled/* | xargs cat | grep ServerName | uniq