Skip to content

Instantly share code, notes, and snippets.

View kennyledet's full-sized avatar

Kendrick Von Ledet kennyledet

View GitHub Profile
@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 / 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("_")])
@kennyledet
kennyledet / csv_to_js_array.py
Created September 8, 2014 03:28
Convert a CSV file to a Javascript Array
def csv_to_js_array(csv_path):
import csv
import os
attributes = []
values = []
with open(csv_path, "rb") as csvfile:
print csvfile
extension String {
/// Truncates the string to length number of characters and
/// appends optional trailing string if longer
func truncate(length: Int, trailing: String? = nil) -> String {
if countElements(self) > length {
return self.substringToIndex(advance(self.startIndex, length)) + (trailing ?? "")
} else {
return self
}
}
@kennyledet
kennyledet / legacy-dynamic-card-grid-height.js
Last active August 29, 2015 14:27
Legacy code for dynmically calculating and setting CSS prop for min-height on results container of product grid items
if ( $(window).width() <= 720 ) {
var _card = $('.product-grid-item');
var cardLen = _card.length;
var cardHeight = _card.height();
var totalCardHeight = cardLen * cardHeight;
$('#results-container').css('min-height', (totalCardHeight+cardHeight) +'px');
}
@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