Skip to content

Instantly share code, notes, and snippets.

@joecliff
joecliff / cryptojs_base64_encrypt_decrypt.js
Last active March 11, 2024 08:00
An example of base64 usage in cryptojs
var CryptoJS = require("crypto-js");//replace thie with script tag in browser env
//encrypt
var rawStr = "hello world!";
var wordArray = CryptoJS.enc.Utf8.parse(rawStr);
var base64 = CryptoJS.enc.Base64.stringify(wordArray);
console.log('encrypted:', base64);
//decrypt
var parsedWordArray = CryptoJS.enc.Base64.parse(base64);
@fehmicansaglam
fehmicansaglam / Application.java
Created February 9, 2012 18:50
Accept range header and write a partial content to the response with Play! Framework.
public static void downloadFile(final Long fileId) throws IOException {
response.setHeader("Accept-Ranges", "bytes");
notFoundIfNull(fileId);
File underlyingFile = ... //load file
String fileName = ...//name of the file
Header rangeHeader = request.headers.get("range");
if (rangeHeader != null) {
throw new PartialContent(underlyingFile, fileName);
@mediaupstream
mediaupstream / json2xml.js
Created December 19, 2011 06:57
json2xml - Convert an xml2js JSON object back to XML
/**
* json2xml - Convert an xml2js JSON object back to XML
*
* @author Derek Anderson
* @copyright 2011 Media Upstream
* @license MIT License
*
* Usage:
*
* json2xml({"Foo": "@": { "baz": "bar", "production":"true" }}, "Test", function(xml){