Skip to content

Instantly share code, notes, and snippets.

@kdmukai
kdmukai / CodeSnippet1.java
Created July 20, 2011 22:39
Extending David Chandler's ObjectifyGenericDao with interfaces
import com.essaytagger.model.BasicUser;
import com.essaytagger.model.Essay;
import com.essaytagger.server.impl.ObjectifyGenericDAO;
// ...
ObjectifyGenericDAO<BasicUser> basicUserDao = new ObjectifyGenericDAO<BasicUser>();
BasicUser user = basicUserDao.get(userId);
ObjectifyGenericDAO<Essay> essayDao = new ObjectifyGenericDAO<Essay>();
@kdmukai
kdmukai / UploadFileToGoogleDocs.java
Created July 23, 2011 19:47
How to upload a File to Google Docs when you can't create a File in Google App Engine!
import com.google.gdata.client.docs.DocsService;
import com.google.gdata.data.MediaContent;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.docs.DocumentListEntry;
import com.google.gdata.data.docs.DocumentListEntry.MediaType;
import com.google.gdata.data.media.MediaByteArraySource;
import com.google.gdata.data.media.MediaSource;
import com.google.gdata.util.ContentType;
// ...skipping to the good part...
@kdmukai
kdmukai / gist:1101813
Created July 23, 2011 19:58
Google's example code to upload a file to Google Docs
DocumentListEntry uploadedEntry = uploadFile("/path/to/your/file.doc", "TitleToUse");
System.out.println("Document now online @ :" + uploadedEntry.getHtmlLink().getHref());
public DocumentListEntry uploadFile(String filepath, String title)
throws IOException, ServiceException {
File file = new File(filepath);
DocumentListEntry newDocument = new DocumentListEntry();
String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
newDocument.setFile(new File(filepath), mimeType);
newDocument.setTitle(new PlainTextConstruct(title));
@kdmukai
kdmukai / EssayManagerExtensions.java
Created July 24, 2011 08:45
Final versions of ObjectifyGenericDAO with interfaces
package com.essaytagger.server.impl;
import com.essaytagger.model.Comment;
import com.essaytagger.model.Essay;
import com.essaytagger.server.IEssayManagerExtensions;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.googlecode.objectify.Key;
/**
* Implementation class for any Essay-specific methods that aren't already handled by ObjectifyGenericDAO<T>.
@kdmukai
kdmukai / BitmapButton.as
Created September 11, 2011 01:44
Customizable ActionScript BitmapButton
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.events.MouseEvent;
/**
* A reusable Button class that can be skinned by Bitmaps
*/
public class BitmapButton extends Sprite {
private var defaultBitmap:Bitmap = new Bitmap();
private var onHoverBitmap:Bitmap = new Bitmap();
@kdmukai
kdmukai / Example1.java
Created November 4, 2011 18:06
_GenericDaoHibernateImpl<T> excerpt with session-safe getHibernateTemplate.save()
Cat oldCat = catDao.get(oldCatId);
Cat newCat = new Cat();
newCat.setName("Whiskers");
newCat.setOwner(oldCat.getOwner());
catDao.save(newCat); // Causes Session conflict because Owner isn't initialized
@kdmukai
kdmukai / IndexServlet.java
Created June 9, 2012 20:08
Adding a page with Java, Tiles, and JSP
package com.essaytagger.web.user.administrator;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tiles.TilesContainer;
import org.apache.tiles.servlet.context.ServletUtil;
@kdmukai
kdmukai / about_us.html
Created June 9, 2012 20:42
Adding a page with Django
{% extends 'visitor/_visitor_base.html' %}
{% block page_title %}About Us{% endblock %}
{% block page_headline_text %}About Us{% endblock %}
{% block page_content %}
This is the About Us text
{% endblock %}
@kdmukai
kdmukai / register.html
Created July 26, 2012 01:16
Facebook registration with django_facebook
{% load url from future %}
<link href="{{ STATIC_URL }}css/facebook.css" type="text/css" rel="stylesheet" media="all" />
{% include 'django_facebook/_facebook_js.html' %}
Register!
<form action="{% url 'facebook_connect' %}?facebook_login=1" method="post">
<a href="javascript:void(0);" style="font-size: 20px;" onclick="F.connect(this.parentNode);">Login or register with facebook</a>
<input type="hidden" value="{% url 'my_post_registration_url' %}" name="register_next" />
@kdmukai
kdmukai / __base_template.html
Last active August 29, 2015 13:56
Simple jQuery approach to a site-wide popup warning or action dialog with a page overlay to dim the background. This should eventually be packaged up as a plugin that can be loaded on a per-page basis rather than living in the __base_template.html
<html>
<body>
<style>
.page_overlay {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;