Skip to content

Instantly share code, notes, and snippets.

@aelaguiz
aelaguiz / gist:478e651e5c0bb763b5e5
Created July 3, 2014 20:38
Data collection on subscribe page
{% extends "base.html" %}
{% macro ship_option(product, discount) %}
{% if product.ship_option_string == "pricedin" %}
<p class="ship_discount sml-text">FREE Shipping
{% if discount %}
<br />Save {{ ((1 - discount) * 100) | int }}%
{% else %}
<br />
{% endif %}
@aelaguiz
aelaguiz / gist:8386014
Created January 12, 2014 15:28
weird behavior of relpath
Python:
os.chdir(path)
cwd = os.getcwd()
print path
print cwd
print os.path.relpath(path, start=cwd)
output:
./themes/bold
@aelaguiz
aelaguiz / dispatching_model.py
Created November 28, 2013 13:22
Dispatching model pattern with sqlalchemy
import sqlalchemy as sqla
import sqlalchemy.ext.declarative as decl
from .signals import signaler
class _hooked(object):
def __init__(self, validate_func, normalize_func, field_name, private_name):
self.validate_func = validate_func
self.normalize_func = normalize_func
self.field_name = field_name
@aelaguiz
aelaguiz / gist:4455549
Last active October 8, 2016 15:13
Quick & Dirty Theano benchmark
import numpy
import theano
import theano.tensor as T
import config
import time
def theano_softmax():
x = T.fmatrix('x')
_y = T.nnet.softmax(x)
@aelaguiz
aelaguiz / theano_softmax
Last active December 10, 2015 15:19
Equivalent straight numpy/python for Theanos softmax function
import numpy
import theano
import theano.tensor as T
def theano_softmax():
x = T.dmatrix('x')
_y = T.nnet.softmax(x)
f = theano.function([x], _y)
return f
@aelaguiz
aelaguiz / gist:864454
Created March 10, 2011 16:58
node.js function to create full directory path (like mkdir -p)
exports.createFullPath = function createFullPath(fullPath, callback) {
var parts = path.dirname(path.normalize(fullPath)).split("/"),
working = '/',
pathList = [];
for(var i = 0, max = parts.length; i < max; i++) {
working = path.join(working, parts[i]);
pathList.push(working);
}
@aelaguiz
aelaguiz / client.js
Created February 28, 2011 16:55
Communications for chat client using message.socket.io
var ChatRoom = function ChatRoom(chatList, inputArea, list) {
var _chatList = chatList,
_inputText = inputArea,
_userList = list,
_nickList = [];
/*
* Handle three events from the communications layer
*/
this.expose = {