Skip to content

Instantly share code, notes, and snippets.

View craigpalermo's full-sized avatar

Craig Palermo craigpalermo

View GitHub Profile
@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 / 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 / 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();
}
});
for object in objects
object['place'] = object['@place']
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
from tweepy import Stream
from tweepy import API
from cleverbot import Cleverbot
import json
import sys
consumer_key = ""
@craigpalermo
craigpalermo / rotate_array.py
Created September 4, 2014 15:15
Interview question, rotate elements in 2D array 90 degrees clockwise
n = 5
arr = []
# populate array
for i in range(0, n):
arr.append([])
for j in range(0, n):
arr[i].append(j)
# print before
@craigpalermo
craigpalermo / Stylus Style Guide.md
Last active August 29, 2015 14:05
A set of general guidelines to create awesome looking stylesheets with Stylus

Stylus Style Guide

Data Exchange is going to use Stylus as its CSS preprocessor. Learn good style, and it will be your friend.

This guide includes content adapted from the Obvious Corporation's LESS style guide for Stylus.

Naming Conventions

@craigpalermo
craigpalermo / move_videos.py
Last active August 29, 2015 14:03
This script moves the largest file in each folder in the directory that it's run from into that directory.
'''
This script moves the largest file from each subdirectory into the
same directory that the script is run from.
Before:
/root
/episode1
e1.avi
...
/episode2
@craigpalermo
craigpalermo / fake_keypress.py
Last active August 29, 2015 14:03
As long as it's running, it simulates pressing the F16 key every 5 seconds to trick messaging clients into thinking that you're still active.
import win32api, win32com.client
import time, sys
# open a shell to type into
shell = win32com.client.Dispatch("WScript.Shell")
while True:
# just some dots to show that it's still running
sys.stdout.write('.')
sys.stdout.flush()
@craigpalermo
craigpalermo / wsgi.py
Last active August 29, 2015 14:03
wsgi.py for django project
import os, sys
path = '/path/to/project'
settings_module = 'myapp.settings'
if path not in sys.path:
sys.path.append(path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)