Skip to content

Instantly share code, notes, and snippets.

@javajack
javajack / gist:3143114
Created July 19, 2012 11:13 — forked from kritzikratzi/gist:1275419
Another way to use play-morphia blobs
package models;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import play.libs.MimeTypes;
import play.modules.morphia.Blob;
<script>
// <snip>
(function (window, document) {
var loader = function () {
var script = document.createElement("script"), tag = document.getElementsByTagName("script")[0];
script.src = "http://errorception.com/projects/" + _errs[0] + "/beacon.js";
tag.parentNode.insertBefore(script, tag);
};
// Wait until window.onload before downloading any more code.
.fc {
direction: ltr;
text-align: left; }
.fc table {
border-collapse: collapse;
border-spacing: 0; }
.fc .btn {
line-height: 1.2em; }
html .fc {
@javajack
javajack / PasswordEncryptionService.java
Created September 26, 2013 07:12
Code to encrypt passwords using PBKDF2, which is a one way encryption scheme. Don't use MD5, use bcrypt or PBKDF2. Only Java SE 6 is required.
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.util.Arrays;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
public class PasswordEncryptionService {
function My_App() {
this.foo = '',
this.bar = '',
this.jQuery = false,
// Initializes our app.
this.init = function(params){
// Set any custom app options.
for ( key in params ) this[key] = params[key];
// ----------------------------------------------------------
// A short snippet for detecting versions of IE:
// Uses a combination of object detection and user-agent
// sniffing.
// ----------------------------------------------------------
// If you're not in IE then:
// ie === NaN // falsy
// If you're in IE then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
package fi.markoa.proto.jersey2.jetty;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class JettyWebApp {
public static void main(String ... args) throws Exception {
Server server = new Server(8090);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/app1");
@javajack
javajack / EmailServiceActor.java
Created November 27, 2013 06:26
http://blog.nemccarthy.me/?p=272 With Akka 2.2-RC1 coming out last night I decided to upgrade. There are a few changes that make DI with Akka in Java much easier. Previously (Akka 2.1) I was using the UntypedActorFactory approach, however in 2.2 this seems that these methods have been deprecated in favor of the Creator approach. Trying to dig ar…
@Component
@org.springframework.context.annotation.Scope("prototype")
public class EmailServiceActor extends UntypedActor {
@Override
public void onReceive(Object message) throws Exception {
//Do actor stuff...
}
}
@javajack
javajack / jquery.gdocsviewer.js
Created December 10, 2013 19:18
A JQuery Plugin for Google Doc Viewer Iframe Embeding http://jsfiddle.net/javajack/4s8bn/embedded/result/
/*
* jQuery.gdocViewer - Embed linked documents using Google Docs Viewer
* Licensed under MIT license.
* Date: 2011/01/16
*
* @author Jawish Hameed
* @version 1.0
*/
(function($){
$.fn.gdocsViewer = function(options) {
@javajack
javajack / redirect-after-post-flash-scope.java
Created December 23, 2013 18:32 — forked from oscarryz/gist:6381954
Spring Redirect After Post With Flash Scope
@RequestMapping(value = "/hola", method = RequestMethod.GET)
public String hola(Model model,
@ModelAttribute("command") Object command,
BindingResult results,
RedirectAttributes redirectAttributes ) {
model.addAttribute("command", command);
ValidationUtils.invokeValidator(validator, command, results);
if (results.hasErrors()) {
redirectAttributes.addFlashAttribute("errors", results.getAllErrors());