Skip to content

Instantly share code, notes, and snippets.

Avatar

Kendrick Ledet kennyledet

View GitHub Profile
@kennyledet
kennyledet / legacy-dynamic-card-grid-height.js
Last active Aug 29, 2015
Legacy code for dynmically calculating and setting CSS prop for min-height on results container of product grid items
View legacy-dynamic-card-grid-height.js
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');
}
View string-truncate.swift
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 Sep 8, 2014
Convert a CSV file to a Javascript Array
View csv_to_js_array.py
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 Aug 14, 2014
Convert an underscore_based_string into CamelCase
View underscore_to_camel_case.py
def underscore_to_camel_case(string):
return ''.join([chunk.capitalize() for chunk in string.split("_")])
@kennyledet
kennyledet / sqlalchemy_dupe_row
Created Jul 19, 2014
SQLAlchemy Duplicate Row
View sqlalchemy_dupe_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 Aug 29, 2015
Draw 4 diamonds (really rotated circles) inside 1 larger diamond using the power of CSS; uses Bootstrap for col spacing
View 4DiamondsInOneHack.html
<style>
/* Diamond Hack CSS */
.diamond {
width: 160px;
height: 160px;
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
View Zsh-extract
# 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 ;;
View 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 Aug 19, 2013
python gif-maker.py {filepath} {start time} {run time} python gif-maker.py movie.mp4 00:00:39 3
View gif-maker.py
# 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 Jun 2, 2013
Scrapes Pypi package list for a random Python module.
View random_pypi_package.py
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)
You can’t perform that action at this time.