Skip to content

Instantly share code, notes, and snippets.

View kennyledet's full-sized avatar

Kendrick Von Ledet kennyledet

View GitHub Profile
@kennyledet
kennyledet / email_with_attachments.py
Created April 27, 2013 22:16
Shows how to access Gmail (or any other IMAP4 server) for new messages under a certain folder or label name. Comments are fairly straightforward; shows how to also get attachments if any exist.
import imaplib
folder_name = 'Inbox'
gm = imaplib.IMAP4_SSL('imap.gmail.com', 993)
gm.login('youraddress@gmail.com', 'password')
status, data = gm.select(folder_name) # select() can select by label or folder name
if status: status, data = gm.search(None, 'UNSEEN') # get new messages only

The idea is to have nginx installed and node installed. I will extend this gist to include how to install those as well, but at the moment, the following assumes you have nginx 0.7.62 and node 0.2.3 installed on a Linux distro (I used Ubuntu).

In a nutshell,

  1. nginx is used to serve static files (css, js, images, etc.)
  2. node serves all the "dynamic" stuff.

So for example, www.foo.com request comes and your css, js, and images get served thru nginx while everything else (the request for say index.html or "/") gets served through node.

  1. nginx listens on port 80.
"use strict";
var httpProxy = require('http-proxy'),
http = require('http'),
accesslog = require('access-log'),
addresses;
var LISTENPORT = 80; //port we're listening to the outside world
var METEORPORT = 3000; //port meteor is run on the guests
var MINIP = 10; //Minimum IP address we can use. Smaller numbers are for admin purposes
@kennyledet
kennyledet / random_pypi_package.py
Created June 2, 2013 11:34
Scrapes Pypi package list for a random Python module.
import urllib2, re, random
html = urllib2.urlopen('https://pypi.python.org/pypi?%3Aaction=index').read()
r = re.compile(r'/pypi/([-A-Za-z0-9\.]+)/([-A-Za-z0-9\.]+)')
pkgName, pkgVersion = random.choice(re.findall(r, html))
print 'Found random package {} {}, located at https://pypi.python.org/pypi/{}/{}'.format(pkgName, pkgVersion, pkgName, pkgVersion)
@kennyledet
kennyledet / gif-maker.py
Created August 19, 2013 05:50
python gif-maker.py {filepath} {start time} {run time} python gif-maker.py movie.mp4 00:00:39 3
# gif-maker.py
# Copyright 2013 Kendrick Ledet
import sys, os
path = sys.argv[1]
start = sys.argv[2]
end = sys.argv[3]
fname = os.path.basename(path)
print fname
@kennyledet
kennyledet / chat.py
Created December 30, 2013 10:42 — forked from gregvish/chat.py
from socket import socket, SO_REUSEADDR, SOL_SOCKET
from asyncio import Task, coroutine, get_event_loop
class Peer(object):
def __init__(self, server, sock, name):
self.loop = server.loop
self.name = name
self._sock = sock
self._server = server
Task(self._peer_handler())
# Allows for any file to be extracted using: x $1
x () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
@kennyledet
kennyledet / 4DiamondsInOneHack.html
Last active August 29, 2015 14:02
Draw 4 diamonds (really rotated circles) inside 1 larger diamond using the power of CSS; uses Bootstrap for col spacing
<style>
/* Diamond Hack CSS */
.diamond {
width: 160px;
height: 160px;
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
@kennyledet
kennyledet / sqlalchemy_dupe_row
Created July 19, 2014 20:50
SQLAlchemy Duplicate Row
def copy_row(model, row, ignored_columns=[]):
copy = model()
for col in row.__table__.columns:
if col.name not in ignored_columns:
try:
copy.__setattr__(col.name, getattr(row, col.name))
except Exception as e:
print e
continue
@kennyledet
kennyledet / underscore_to_camel_case.py
Created August 14, 2014 19:13
Convert an underscore_based_string into CamelCase
def underscore_to_camel_case(string):
return ''.join([chunk.capitalize() for chunk in string.split("_")])