Skip to content

Instantly share code, notes, and snippets.

@mallim
mallim / stream_logging.js
Created June 22, 2014 01:02
Console logging stream. Useful for node stream debugging
var es = require('event-stream');
var logger = es.mapSync(function (data) { //create a stream that logs to stderr,
console.error(data);
return data;
});
.exec(http("Goto Your Desired URL")
.get("http://THIS_SHOULD_BE_YOUR_URL")
.check(
status.is(200),
bodyString.saveAs("responseBody")
)
)
.exec(
session => {
// You can do whatever you want with the string
.exec(http("PERFORM A FILE UPLOAD")
.post("YOUR_DESIRED_URL_FOR_UPLOAD")
.body(ELFileBody("THE_FILE_TO_UPLOAD"))
.check(
status.is(200),
).asMultipartForm)
@mallim
mallim / ErrorLog.java
Created April 7, 2015 01:40
Stacktrace of Error Encountered @ Weblogic 12c, JDK 1.7, Eclipse 2.6.0
####<Apr 6, 2015 7:42:25 PM SGT> <Error> <Class Loaders> <ISPS-APP> <AdminServer> <[STANDBY] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1428320545119> <BEA-2162500> <Class, org.eclipse.persistence.internal.indirection.jdk8.IndirectCollectionsProvider, was compiled with an incompatible version of Java. Make sure that all the classes needed by the application have been compiled with a compatible java version. java.lang.UnsupportedClassVersionError: org/eclipse/persistence/internal/indirection/jdk8/IndirectCollectionsProvider : Unsupported major.minor version 52.0
java.lang.UnsupportedClassVersionError: org/eclipse/persistence/internal/indirection/jdk8/IndirectCollectionsProvider : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at weblogic.utils.classloaders.GenericClassLoader.defineCl
@mallim
mallim / WebSecurityConfig.java
Created June 27, 2014 13:31
Spring Boot's Spring Security Web Security Config
import org.sbangular.security.UnauthorisedEntryPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
@mallim
mallim / unit.js
Last active December 18, 2015 21:48 — forked from trek/unit.js
This code has been tested to work with casperjs 1.0.2 and phantomjs 1.9.1. After writing this, then I managed to get mocha-phantomjs (https://github.com/metaskills/mocha-phantomjs) to work and I switch to that. Primarily because mocha-phantomjs allows the usage of mocha's reporter straight without further customization. Additional things feature…
// Check for phantom
if ( !phantom.casperLoaded ) {
console.log( 'This script must be invoked using the casperjs executable' );
phantom.exit( 1 );
}
// get a Casper object.
// See http://casperjs.org/
// Instantiate casper
var casper = require('casper').create({
@mallim
mallim / preload.js
Created September 6, 2013 11:01
How to load external template in marionette if not using requirejs? Get the code from http://johndavidmathis.wordpress.com/2012/09/13/preloading-backbone-marionette-templates-2/
// Take note to change the source code for the correct path
// Example of using when there are multiple templates
var preloading = Backbone.Marionette.TemplateCache.preloadTemplates(['template1','template2'], this);
$.when(preloading).done(function() {
// Do something
});
@mallim
mallim / json_parse_eg.js
Created September 6, 2013 11:24
How to get a string from java backend and pass it to backbone model or collection?
// Within a jsp page
<script>
var options.saved_values=JSON.parse('${it.json_string_from_Java}');
var theBackboneModel = new TheBackboneModel(options.saved_values,{parse:true});
</script>
@mallim
mallim / jersey_jackson.java
Created September 6, 2013 11:29
Jersey + Jackson can map to a String and a Map<String,Object>
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/some_path")
@mallim
mallim / express_example.js
Created September 6, 2013 11:41
Code sample to run express (with Handlebars as the view engine)
var express = require('express');
var cons = require('consolidate');
var http = require('http');
var reload = require('reload');
var app = express();
var server = http.createServer(app);
// Assign the handlebars engine to .html files
app.engine('html', cons.handlebars);