Skip to content

Instantly share code, notes, and snippets.

View hzbd's full-sized avatar
I may be slow to respond.

hzbd

I may be slow to respond.
View GitHub Profile
class ImageWithThumbnail(models.Model):
name = models.CharField(max_length = 255)
image = models.ImageField(upload_to=settings.UPLOAD_ROOT,max_length=500,blank=True,null=True)
thumbnail = models.ImageField(upload_to=settings.UPLOAD_ROOT,max_length=500,blank=True,null=True)
def create_thumbnail(self):
# original code for this method came from
# http://snipt.net/danfreak/generate-thumbnails-in-django-with-pil/
@hzbd
hzbd / share_tp
Created March 8, 2014 11:07
Django Share button template
{% autoescape on %}
{% with "http://carlosvin.alwaysdate.net" as host %}
{% with "Share in" as share_txt %}
{% with "twitter" as service %}
<a href="http://twitter.com/share?url={{ host }}{{ page_url }}&amp;text={{ title }}" target="_blank" title="{{ share_txt }} {{ service }}">
<img src="http://carlosvin.alwaysdate.net/templates/img/tw.png" alt="{{ share_txt }} {{ service }}"/>
</a>
{% endwith%}
/* ===================================================
* jQuery SelectAll plugin
* ===================================================
* @author: https://gist.github.com/Leegorous
* @license: Licensed under the Apache License, Version 2.0 (the "License"),
* see http://www.apache.org/licenses/LICENSE-2.0
* ===================================================
*
* Example:
*
@hzbd
hzbd / addElements.html
Created August 16, 2014 17:40
auto adding a element by js.
<html>
<head>
<title>Testing</title>
<script language="javascript">
fields = 1;
function addInput() {
if (fields < 4) {
document.getElementById('text').innerHTML += "<input type='file'"+ "name=" + "thumdals" + fields + " value=''/><br />";
fields += 1;
} else {
#Hadoop 2.6.0 Multinode cluster Setup
From Blog http://www.michael-noll.com/tutorials/running-hadoop-on-ubuntu-linux-multi-node-cluster/
###Machine 1(master).
Prequisite:
java version
java -version
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@hzbd
hzbd / gist:4723104
Created February 6, 2013 15:01 — forked from saga/gist:4137880
#!/usr/bin/env python
import simplejson
import logging
import random
import re
import datetime
import string
import time
import sys
import urllib
@hzbd
hzbd / Json_encoder.py
Created February 11, 2013 05:38
Implementation of JSONEncoder
"""Implementation of JSONEncoder
"""
from __future__ import absolute_import
import re
from operator import itemgetter
from decimal import Decimal
from .compat import u, unichr, binary_type, string_types, integer_types, PY3
def _import_speedups():
try:
from . import _speedups
@hzbd
hzbd / Appfog_django_setting.py
Created February 11, 2013 05:41
Appfog a simple django_setting.py for Postgresql-9.1
import json, psycopg2
vcap_services = json.loads(os.environ['VCAP_SERVICES'])
postgres_srv = vcap_services['postgresql-9.1'][0]
try:
cred = postgres_srv['credentials']
except KeyError,ke:
print >> sys.stderr, "VCAP_SERVICES = %s" % str(vcap_services)
raise ke
DATABASES = {
@hzbd
hzbd / SendMail.py
Created April 18, 2013 15:44
using optparse to update sendmail script.
#!/usr/bin/env python
import smtplib
import sys
from optparse import OptionParser
def initialize_smtp_server(smtpserver, smtpport, email, pwd):
'''
This function initializes and greets the SMTP server.
It logs in using the provided credentials and returns the