Skip to content

Instantly share code, notes, and snippets.

View kennyledet's full-sized avatar

Kendrick Von Ledet kennyledet

View GitHub Profile
@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');
}
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 / 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
@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 / 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 / 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);
# 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 / 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())
@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 / 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)