Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE HTML>
<html>
<head>
<title> Canvas Test</title>
</head>
<body>
<canvas id="canvas">
<script>
canvas.height = window.screen.height;
canvas.width = window.screen.width;
@jsfeng
jsfeng / gist:4076602
Created November 15, 2012 04:19
Pouring.scala
package streams
class Pouring (capacity : Vector[Int]) {
//States
type State = Vector[Int]
val initialState = capacity map (x => 0)
//Moves
trait Move {
@jsfeng
jsfeng / dyanmicAddChart.mxml
Created October 26, 2012 14:56
Dyanmic Add Flex Chart Series
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.charts.series.ColumnSeries;
import mx.charts.series.BarSeries;
import mx.charts.series.BarSet;
import mx.collections.ArrayCollection;
import mx.charts.ColumnChart;
@jsfeng
jsfeng / CryptoClassLoader.java
Created September 2, 2012 02:09
CryptoClassLoader
/**
* This class loader loads encrypted class files.
*/
class CryptoClassLoader extends ClassLoader
{
/**
* Constructs a crypto class loader.
* @param k the decryption key
*/
public CryptoClassLoader(int k)
@jsfeng
jsfeng / AmfProvider.java
Created August 17, 2012 14:29
AMF Provider for REST service
package net.java.ws.providers;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
@jsfeng
jsfeng / FileServlet.java
Created May 7, 2012 19:31
FileServlet supporting resume, caching and GZIP
/*
* net/balusc/webapp/FileServlet.java
*
* Copyright (C) 2009 BalusC
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
@jsfeng
jsfeng / SimpleHashUtil.java
Created May 7, 2012 18:33
Simple Hash Utility Tool
import java.util.Random;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import org.apache.commons.codec.binary.Base64;
public class SimpleHashUtil {
/**
* Generates a hash for the given plain text value and returns a
@jsfeng
jsfeng / Cryptographer.java
Created May 7, 2012 18:31
Cryptographer encryption /decryption
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
@jsfeng
jsfeng / StrutsPreventDoubleSubmit.md
Created May 3, 2012 14:15
Struts Prevent Double Submission

On initial request:

  • Call saveToken(request) in your Action class
  • Forward to the JSP displaying the form.

On form submit:

  • Have the Action check if isTokenValid(request)
  • If true, process request then call resetToken(); otherwise, we're dealing with a double-submit and will skip processing it.

What's happening under the hood:

@jsfeng
jsfeng / upload.jsp
Created April 12, 2012 18:25
Struts upload JSP
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html:html locale="true">
<head>
<title>Struts File Upload Example</title>
<html:base/>
</head>
<body bgcolor="white">
<html:form action="/FileUpload" method="post" enctype="multipart/form-data">